PHP - Assigning Php Variable Value To Form Element Value Not Working
Hello Everyone,
I am new to forum and could use some help with some php code that isn't working. I am very new to php/html/javascript and all of what I have learned, I learned from forums like this one so first....thank you! I am trying to assign a value from a php variable to the value of my form element. I'm sure there must be a way to do this but I can't seem to get the syntax right. here is my code... first I set the value of $loginname elsewhere in the script like so... <?php $loginname =strtolower(htmlspecialchars(strip_tags($_GET["loginname"]))); ?> This part works fine.. Then I try to set the value of my hidden text field inside the form to the value of $loginname to be passed to a javascript program. Everything works except that the value passed ends up being <?echo and not the expected user name inside of $loginname. <?php echo '<form name ="currentactivity" Id="currentactivity" action="<?php'.htmlspecialchars($_SERVER['PHP_SELF']).'?>" method="post">'; echo '<fieldset><legend><b>Your Current Activity Information</b></legend>'; echo '<input type="text" name="loginnm" style="visibility: hidden" value="<?php echo $loginname;?>">'; echo "<label for='myactivities'>Activity Name:</label>"; echo "<select name='myactivities' Id='myactivities' onchange=\"showdetails(this.form)\" value=''>"; echo "<option value = 'Select an activity'>Select an activity</option>"; for ($i = 1; $i <=$rowcount; $i++) { echo"<option value=$row[activity_name]>$row[activity_name] </option>"; $row = mysql_fetch_array($result); } echo "</select>"; echo '</fieldset>'; echo '</form>'; ?> Please note..the rest of the code is working perfectly, it is just this one value I can't seem to get. Any help you can give will be greatly appreciated. Similar Tutorialshi there, i'm trying to put a message in the footer of a page which welcomes a person who is logged in with his/her name, using sessions of course; when i place this: Code: [Select] $username = $_SESSION['valid_user']; in the footer before the echo: Code: [Select] echo "You are logged in as $username"; but the session is also needed before the footer to use the username for other things , such as -checking his credit- so if place in footer the footer shows name in browser but checking credit would not happen as the assignment is at the buttom. IF i place the assignment above at the top of the file: everything works for the user and checking credit ..etc...but the footer is not there... cud not put this any clearer..sorry...hope if someone cud help...thanks Hi all, I can't seem to designate an array key by using a variable and I was wondering if this is possible. I'm looking to do something like this: Code: [Select] <?php $key = "apple"; $arr = array($key => "fruit"); ?> Any suggestions would be appreciated! hi, i am updating records from database using ajax and javascript on php page. The result is displayed inside a div (<div id="show"></div>). Now i want to assign the content of the above div(say y) to php variable for further calculations. How can i assign the value displayed in div tag to a php variable? Thanks. Hi folks, I was wondering how to do this. I want the if statement to detect if the query string has any of these values. so im trying to assign them all to the same variable. However, this code wont work. Whats the trick here? <?php $primary=$_GET['intro']; $primary=$_GET['port']; $primary=$_GET['about']; $primary=$_GET['contact']; if(isset($primary)){ echo "<img src='graphics/left-a.png'>";} else {echo "<img src='graphics/leftb.png'>";}?> Hi, I have just started creating my first class in php. I'm trying to assign $_SERVER['REMOTE_ADDR']; to a protected variable but I keep getting an error message. I'm still trying to get my head around oop php. My current code is "protected $user_ip = $_SERVER['REMOTE_ADDR'];" and the error message is "Parse error: syntax error, unexpected T_VARIABLE". Hello, I am creating a class which contains one private function that deals with connecting to a SQL Server and executing the sql that is passed in to that function. I have defined a class variable which is assigned the value of sqlsrv_query like so. $this->QueryResult = sqlsrv_query($conn,$sql); I have placed private $QueryResult at the top of my class. The other public methods call this private function to assign the result set to the class variable, the private method returns and then the public methods loop through the results array like so. while($row = sqlsrv_fetch_array($this->QueryResult)) .. but the while loop never gets entered. If I declare everything in the same method then it works, however there are going to be several public methods that will use this private method and I don't want to duplicate all the database coding. Hope someone can help Okay, really newbie question, but for this code... Code: [Select] <!-- Gender --> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value="">--</option> <option value="F">Female</option> <option value="M">Male</option> </select> 1.) How do I assign a variable to this? 2.) How do I make this "sticky"? Here is how I have usually done other form types... Code: [Select] <!-- First Name --> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" type="text" maxlength="30" value="<?php if(isset($firstName)){echo htmlentities($firstName, ENT_QUOTES);} ?>" /><!-- Sticky Field --> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> Oh, by the way, at the top of my PHP file I have this code... Code: [Select] if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); Thanks, Debbie I am facing problem to execute query by assigning NULL value to a variable and then executing query.In MySQL DB four fields Mobile,landline, pincode,dob are set as integer and date(for dob) respectively.The default is set as NULL and NULL option is selected as yes.All these fields are not mandatory.The problem is that when I edit the form my keeping the value as empty in DB these are saved as 0, 0 , 0 & 0000-00-00 inspite of Null. I have tried everything but still the defect persist. Please help me to come out of the problem The code, I have used: <?php //require_once 'includes/config.php'; $dbusername = $_POST['email']; $dbfirstname = $_POST['first_name']; $dblastname = $_POST['last_name']; //$dbmobile_number = $_POST['mobile']; if (isset($_POST['mobile'])) { $dbmobile_number = $_POST['mobile']; } else { $dbmobile_number = "NULL"; } $dblandline_number = $_POST['landline']; $dbdob = $_POST['dob']; if(isset($_POST['is_email'])) { $dbSubscribe_Email_Alert = '1'; } else { $dbSubscribe_Email_Alert = '0'; } if(isset($_POST['is_sms'])) { $dbSubscribe_SMS = 0; } else { $dbSubscribe_SMS = 0; } $dbAddress_firstname = $_POST['shipping_first_name']; $dbAddress_lastname = $_POST['shipping_last_name']; $dbAddress = $_POST['shipping_address']; $dbcity = $_POST['shipping_city']; $dbpincode = $_POST['shipping_pincode']; $dbstate = $_POST['shipping_state']; $dbcountry = $_POST['shipping_country']; echo "Welcome".$dbusername; //if($_POST['btnSave']) //if ($_POST['btnSave']) //{ //echo "Inside query loop"; $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("salebees") or die ("Couldn't find DB"); //$query = mysql_query("SELECT * FROM users WHERE username='$username'"); $query = mysql_query("update users set firstname = '$dbfirstname', lastname = '$dblastname', mobile_number = '$dbmobile_number', landline_number = '$dblandline_number', dob = '$dbdob', Subscribe_Email_Alert = '$dbSubscribe_Email_Alert', Subscribe_SMS = '$dbSubscribe_SMS', Address_firstname = '$dbAddress_firstname', Address_lastname = '$dbAddress_lastname', Address = '$dbAddress', city = '$dbcity', pincode = '$dbpincode', state = '$dbstate', country = '$dbcountry' where username = '$dbusername' "); header("location:my_account.php"); //} //else //{ //die(); //} ?> hey guys, I'm quite new to PHP and i was wondering if someone would be able to help me out with this. The code i have checks the database to see if a user has provided a Vimeo ID. If they haven't, $video_check will equal a line of html that says the user hasn't added any videos to their portfolio. If the a vimeo ID is present, i want $video_check to equal a bunch of html and css with a foreach function inside that is used to display the users videos from vimeo. The foreach function works fine when its not assigned to the $video_check variable. How do i structure it so that it displays correctly? If you click on videos on this page you might get a better idea of what i'm talking about. http://www.myfilmportfolio.ie/profile.php?id=33 and here is the code i'm having the problem with: /////// check if user has provided vimeo id ////////////////////////// $vimeoID = $row["vimeoID"]; $video_check=''; if (empty($vimeoID)){ $video_check = '<h3>'.$firstname .' has not added any videos to their portfolio</h3>'; } else{ $video_check = '<div id="stats"> <div style="clear: both;"></div> </div> <div id="wrapper"> <div id="embed"></div> <div id="thumbs"> <ul> <?php foreach ($videos->video as $video): ?> <li> <h4><?=$video->title?></h4> <a href="<?php echo $video->url ?>"> <img src="<?php echo $video->thumbnail_medium ?>" class="thumb" /></a> <p><?=$video->description?></p> <br /> </li> <?php endforeach ?> </ul> </div> </div>'; } if anyone could help me out id really appreciate it. Cheers, G This works: Code: [Select] form action="http://localhost/mysite/css/screen.css" method="post"> This does not work: Code: [Select] <?php $link_1 = "http://localhost/mysite/css/screen.css" ; $link_2 = '"' . "http://localhost/mysite/css/screen.css" .'"' ; ?> <form action=<?php echo $link_1;?> method="post"> <form action=<?php echo $link_2;?> method="post"> Why do neither of the PHP variables work? Thanks! I get the following error when I try to pass a value to a methiod in a loop: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 This one has me very baffled. It will work the first time, and seems to work every other time, so I have no clue what is wrong. Here is the code: This code is part of my "display" class: function display_partner ($type,$loc,$rand=0,$narrow=0) { $this->partners = new partner($this->cxn); $display = ' <div id="cont_info" class="partner-list"> <div> <h3 class="settings">'.ucfirst($loc).' '.ucfirst($type).last_letter($type).'s</h3> </div> <div class="settings-value" style="height:12px;padding:0;margin:0;text-align:right;padding-right:10px;"> <a href="" class="trunc">Add your organization to this list</a></p> </div> <div style="height:2px;padding:0;margin:0;"> <hr class="account" /> </div> '; $ids = $this->partners->get_partners_list($type,$loc,$rand); for ($b=0;$b<sizeof($ids->id);$b++) { $this->partnerID = $ids->id[$b]; $display .= ($narrow)? $this->card_partner_narr():$this->card_partner(); if ($b!=(sizeof($ids->id)-1)) { $display .= '<hr class="account" />'; } } if (sizeof($ids->id)==0) { $display .= '<div style="color:#999999;display:line;text-align:center;height:20px;">No Partners found for '.ucfirst($loc).' '.ucfirst($type).'</div>'; } $display .= ' </div>'; return $display; } function card_partner () { $this->partners->set_partner_id($this->partnerID); $part_info = $this->partners->get_partner_info(); if ($part_info) { $display .= ' <table class="settings"> <tr> '.$this->show_if($part_info['partLogo']['val'],'<td class="settings-value" rowspan="2"><img src="'.LOGO_FOLDER.$part_info['partLogo']['val'].'" '.resize_img(LOGO_FOLDER.$part_info['partLogo']['val'],175).'alt="'.$part_info['partName']['val'].'" /></td>').' <td class="settings-value" colspan="2"><h5>'.$part_info['partName']['val'].'</h5></td> </tr> <tr> <td class="settings-value"> <span style="color:999999;">'.$part_info['partAddress']['val'].'<br /> '.$part_info['partCity']['val'].', '.$part_info['partST']['val'].' '.$part_info['partZIP']['val'].'<br /> '.$part_info['partPhone']['val'].'</span><br /> <a href="'.$this->form->show_href($part_info['partWeb']['val']).'" target="_blank">'.$part_info['partWeb']['val'].'</a> </td> <td class="settings-value">'.$part_info['partInfo']['val'].'</td> </tr> </table> '; } return $display; } This code is part of my "partners" class: function set_partner_id($partID) { echo '<p>partID: '.$partID.' '.gettype($partID).'<br> $this->partner->id: '.$this->partner->id.'</p>'; $this->partner->id = $partID; ///*** ERROR HAPPENS HERE ***/ echo '<p>id set: '.$this->partner->id.'<br> $this->partner->id: '.$this->partner->id.'</p><hr>'; } function get_partner_id() { return $this->partner->id; } // gets user info at login function get_partner_info() { $this->partner = $this->cxn->proc_info('partner','partID',$this->partner->id);//$this->partner->id return $this->partner; } The following is the output generated: partID: 24 string $this->partner->id: id set: 24 $this->partner->id: 24 partID: 26 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: partID: 17 string $this->partner->id: id set: 17 $this->partner->id: 17 partID: 25 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: As you can see, the value passes to $this->set_partner_id($partID) each time. It is formatted as a string. When it assigns the value to $this->partner->id, however, sometimes it works, and sometimes it doesn't. It's probably something obvious, but I've racked my brain to see what it is. Any ideas? Usually it would be something like:
$("#lblpasswordmessage").html("Password is too short");But how do you do it using a variable? For example say the variable is called 'pwm'; $("#pwm").html("Password is too short"); $("pwm").html("Password is too short"); $(pwm).html("Password is too short");Thanks Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu I have a script that adds points together based upon the placing. This is the actual script: Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? Hi, i have problem with editing register form over Inspect element or when u press F12 in mozilla or chrome. When u select country u can edit form on F12 and change country value so form save it like that in database. Problem is because its in foreach loop and i cant get a check if country in post variable is valid, and compare it with that in database. In my $_POST variable country is stored like ' Croatia, hr ' and in database its like 'id, name, alpha_2, alpha_3'.
So can i find value i need for example Albania and al wihout any loop ?
// if user is logged in redirect him to index page if ($general->is_logged() === true) { header('Location: index.php'); exit(); } // get list of countries $country = $teams->get_country(); require_once 'core/classes/recaptchalib.php'; $publickey = "***********************"; $privatekey = "***********************"; // process form if (isset($_POST['register'])) { if (isset($_POST['username']) && isset($_POST['nickname']) && isset($_POST['password']) && isset($_POST['repeat_password']) && isset($_POST['email']) && isset($_POST['repeat_email']) && isset($_POST['gender']) && isset($_POST['country']) && isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_challenge_field'])) { $username = trim($general->safe_input($_POST['username'])); $nickname = trim($general->safe_input($_POST['nickname'])); $password = trim($general->safe_input($_POST['password'])); $rpassword = trim($general->safe_input($_POST['repeat_password'])); $email = trim($general->safe_input($_POST['email'])); $remail = trim($general->safe_input($_POST['repeat_email'])); $gender = trim($general->safe_input($_POST['gender'])); $cntry = $general->safe_input($_POST['country']); $date_registered = time(); $password_hash = $general->safepass($password); // captcha $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); // if username is empty if (empty($username)) { $error[] = 'Username is empty.'; // if username already exists } elseif ($users->user_exists($username) === true) { $error[] = 'Username in use, please choose another.'; // username must be between 3 and 20 characters long } elseif (strlen($username) < 3 || strlen($username) > 20) { $error[] = 'Username must be between 3 and 20 charaters long.'; } // if nickname is empty if (empty($nickname)) { $error[] = 'Nickname is empty.'; // if nickname in use } elseif ($users->nick_exists($nickname) === true) { $error[] = 'Nickname in use, please choose another.'; // nickname must be between 3 and 20 characters long } elseif (strlen($nickname) < 3 || strlen($nickname) > 20) { $error[] = 'Nickname must be between 3 and 20 characters long.'; } // if passowrd field is empty if (empty($password)) { $error[] = 'Password filed is empty.'; } // if password repeat field is empty if (empty($rpassword)) { $error[] = 'Repeat password filed is empty'; } // if password and repeat password is not empty if (!empty($password) && !empty($rpassword)) { // passwords match ? if not throw error message if ($password != $rpassword) { $error[] = 'Passwords don\'t match.'; // password must be between 6 and 30 characters long } elseif (strlen($password) < 6 || strlen($password) > 30) { $error[] = 'Password must be between 6 and 30 characters long.'; } } // is email empty if (empty($email)) { $error[] = 'Email filed is empty.'; } // is repeat email is empty if (empty($remail)) { $error[] = 'Repeat email filed is empty.'; } // if email and repeat email is not empty if (!empty($email) && !empty($remail)) { // if emails are not same if ($email != $remail) { $error[] = 'Emails don\'t match.'; // if email and repeat email is same } elseif ($email == $remail) { // is email valid if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error[] = 'Invalid email format.'; // is email in use } elseif ($users->email_exists($email) === true) { $error[] = 'Email in use, please choose another.'; // email must be between 10 and 30 characters long } elseif (strlen($email) < 10 || strlen($email) > 30) { $error[] = 'Email must be between 10 and 30 characters long.'; } } } // if gender is empty if (empty($gender)) { $error[] = 'Please select gender.'; } // if gender is not empty if (!empty($gender)) { // if gender is Male or Female if ($gender == 'Male') { $gender = 'Male'; } elseif ($gender == 'Female') { $gender = 'Female'; } else { $error[] = 'Invalid gender.'; } } // if country is empty if (empty($cntry)) { $error[] = 'Please select country.'; } // check if country is valid if (!empty($cntry)) { // $newCountry['0'] is name key // $newCountry['1'] is alpha_2 key $newCountry = explode(',', $cntry); if (in_array($newCountry['0'], $country['name'])) { $error[] = 'VALID.'; } else { $error[] = 'Invalid country.'; } } // check if capthha is valid if (!$resp->is_valid) { $error[] = 'Invalid captcha code.'; } // if no errors register user if (empty($error) === true) { //$add_user = $users->register_user($username, $password_hash, $email, $gender, $date_registered, $cntry, $nickname); unset($_POST); // clean $_post variable echo 'REGISTER USER !'; } /* if ($DBH->lastInsertId()) { header('Location: index.php?page=register_success'); exit(); } else { $error = '<p class="error-msg">There was a problem, please try again.</p>'; }*/ } } ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'clean' }; </script> <h3>Register</h3> <?php if (!empty($error)) { echo '<div style="padding:10px;margin:0 10px;border:1px solid #f3f3f3;background:#E35454;color:#fff;"><ul style="margin:0 0 0 20px;">'; foreach ($error as $error) { echo '<li>'.$error. '</li>'; } echo '</ul></div>'; } ?> <form action="" method="POST" class="register-form"> <input type="text" name="username" size="40" maxlength="20" placeholder="Username" value="<?php if (isset($_POST['username'])) { echo htmlentities($_POST['username'], ENT_QUOTES, "UTF-8"); } ?>" required> <input type="text" name="nickname" size="40" maxlength="20" placeholder="Nickname" value="<?php if (isset($_POST['nickname'])) { echo htmlentities($_POST['nickname'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br /> <input type="password" name="password" size="40" maxlength="30" placeholder="Password" required> <input type="password" name="repeat_password" size="40" maxlength="30" placeholder="Repeat password" required><br /><br /> <input type="text" name="email" size="40" maxlength="30" placeholder="Email" value="<?php if (isset($_POST['email'])) { echo htmlentities($_POST['email'], ENT_QUOTES, "UTF-8"); } ?>" required> <input type="text" name="repeat_email" size="40" maxlength="30" placeholder="Repeat email" value="<?php if (isset($_POST['repeat_email'])) { echo htmlentities($_POST['repeat_email'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br /> <select name="gender" required> <option value="">Select gender</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> <select name="country" style="width: 215px;" required> <option value="">Select country</option> <?php foreach ($country as $key) { echo '<option value="'.$key['name'].','.$key['alpha_2'].'">'.$key['name'].'</option>'; } ?> </select> <br><br> <center><?php echo recaptcha_get_html($publickey); ?></center> <br> <center><input type="submit" name="register" value="Register" class="small-button"></center> </form> Dear All I have a form say i have selected Volva from drop down box . So without clicking on submit button when i move to next field that is `<input>` the value that is volva should get store in php variable <html> <body> <form action=""> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> <input type="text" name="abc" /> </form> </body> </html> Hi guys, I have a problem with the code on below. When I input the value into $name and $email method, the page come into blank page. <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $name = clean($_GET['name']); $email = clean($_GET['email']); $comments = clean($_GET['comments']); $type = clean($_GET['type']); if($name == '') { $errmsg_arr[] = 'name or member ID missing'; $errflag = true; } if($email == '') { $errmsg_arr[] = 'email address ID missing'; $errflag = true; } else { } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; // echo "tested"; } if(isset($_GET['email'])) { $insert[] = 'email = \'' . clean($_GET['email']) . '\''; } if(isset($_GET['type'])) { $insert[] = 'type = \'' . clean($_GET['type']) . '\''; } if(isset($_GET['comments'])) { $insert[] = 'comments = \'' . clean($_GET['comments']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } echo "Thank you for sent us your email"; } } } ?> There must be the problem coming from this: if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } I am not sure where the problem is, so please could you help me?? Hi, I have a variable named $siteName stored in the server.php file in the data directory data/server.php Now in the header.php page I want to retrieve the $siteName variable so it can be used in the header information. This is what I have but it isnt working. server.php Code: [Select] <?php $siteName = 'My+Test+Site'; ?><?php $adminEmail = 'pwithers2009@hotmail.co.uk'; ?><?php $sendmailLoc = '/usr/sbin/sendmail'; ?><?php $imgdir = 'http://www.tropicsbay.co.uk/images/'; ?><?php $imgdirbase = '/home/tropicsb/public_html/images/'; ?> header.php Code: [Select] <?php include("data/server.php"); $siteName = $_GET['siteName']; echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>$siteName Admin Panel</title> <link rel="stylesheet" href="admin.css" type="text/css" /> </head> <div id="pagehead"> <div id="navigation"> <img alt="" src="images/leftNav.gif" height="32" width="4" id="leftNav" /> <img alt="" src="images/rightNav.gif" height="32" width="4" id="rightNav" /> <div id="globalLink"> <a href="admin.php?cmd=manage&username=admin&password=$adminpw" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Users</a><a href="admin.php?cmd=editTemplate&username=admin&password=$adminpw" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Templates</a><a href="admin.php?cmd=mysqlBackup&username=admin&password=$adminpw" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Database</a><a href="admin.php?cmd=paymentLog&username=admin&password=$adminpw" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Payment</a><a href="admin.php?cmd=profileFields&username=admin&password=$adminpw" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Setup</a><a href="admin.php?cmd=changeAdminpw&username=admin&password=$adminpw" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">Preferences</a><a href="admin.php?cmd=logout&username=admin&password=$adminpw" id="gl7" class="glink" onmouseover="ehandler(event,menuitem6);">Logout</a></div> </div></div> <div id="pagelayout"> <img alt="" src="images/leftCurve.gif" height="6" width="6" id="left" /> <img alt="" src="images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h2>$siteName Admin Panel<h2> </div>'; ?> Any ideas on how to do this, it seems to work ok in one of my other scripts. Thanks i've been programming in PHP for years, and have done a substantial amount of work on applications of this nature. this problem has me stumped, not because i can't fix it (i did), but because i have no idea what the problem is. there are hundreds of lines of code involved here, so i'll break it down into a post-friendly format. take this for example, and forgive any typos. it's late, and i've been beating my head against this for over two hours... =\ this is from my form: Code: [Select] /* ... numerous form fields being passed as $_REQUEST arrays */ <input type="hidden" name="option_id[]" value="<?php print $query_result->option_id; ?>" /> /* a couple hundred more lines */ here's the DB update handler: Code: [Select] if (!empty($_REQUEST['option_name'])) { foreach ($_REQUEST['option_name'] as $k => $v) { if ($v != '') { $option_id = $_REQUEST['option_id'][$k]; $option_name = $_REQUEST['option_name'][$k]; $option_price = $_REQUEST['option_price'][$k]; $option_desc = htmlentities($_REQUEST['option_desc'][$k], ENT_QUOTES); if (!$option_id = '') { $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $option_id "'"; if (!$query_function($sql_options)) { $error = true; } } else { $sql_options = "INSERT INTO table (option_name, option_price, option_desc)" . " VALUES ('" . $option_name . "', '" . $option_price . "', '" . $option_desc . "')"; if (!$query_function($sql_options)) { $error = true; } } } } } the above code doesn't post to the database because the $option_id variable returns a null value. however, if i replace the $option_id variable where i build the query string with $_REQUEST['option_id'], it works just fine. Code: [Select] /* in relevant part */ $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $_REQUEST['option_id'] . "'"; needless to say i was infuriated by having spent a couple of hours to come to this conclusion. i only used the variables in the first place because i need to expand the function that this lives inside and i don't want to have to type $_REQUESTs over and over. the only thing i can think is that it might be a type issue. the data is coming out of the mysql table from an INT field and being placed into the value for the hidden field straight from the row collection. would forcing a variant data type by not strongly typing my variable have caused this problem? i haven't tested the theory because i'm still too ticked off to open my code editor. i'm bouncing this off the community and posting my experience in the hope that it might help someone who comes after. I've been baffled by this for 2 days now and cannot figure it out after exhaustive searches. I'd like to think I'm doing this correctly, but cannot get it to work.
I'm trying to use a variable within a query WHERE statement, and it shows 0 results. If I directly hardcode the text instead of using the variable, it works. The variable is pulling from a $_GET, and if I echo that variable, it is showing the correct text.
Here's my code:
$Domain = $_GET['Domain']; $result = mysql_query(SELECT Code, Title, Domain, Status FROM tablename WHERE Domain="$Domain" ORDER BY Code');If I swap out "$Domain" for direct text, like "ABC", it works. I have tried swapping out the quotes and single quotes throughout the statement, removing the quotes around $Domain, concatenating the statement separately....all yield erros or the same result. And as stated, if I echo $Domain, it shows "ABC" (or whatever it's supposed to show), so i know it's pulling correctly from the $_GET. Anyone know what I'm doing wrong? |