asherinho Posted August 1, 2007 Share Posted August 1, 2007 Iam a beginer to php thats why i frequently ask questions. I have a table in the database havin 3 fields:- firstname,lastname,age.i want to fetch the age basing on the firstname selected from the form's select menu which has all the names present in the firstname field.the form is saved as php since i had to first fetch the names to be available in the select menu.here are the codes and the warning i got <?php $db=mysql_connect("localhost","root"); mysql_select_db("my_db",$db); $query="SELECT age FROM person WHERE firstname=$firstname"; $result=mysql_query($query); $record=mysql_fetch_assoc($result); list($fieldname,$fieldvalue)=each($record); echo $fieldvalue; ?> Warning: Variable passed to each() is not an array or object in C:\Program Files\xampp\webalizer\age.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/62825-another-help-please/ Share on other sites More sharing options...
trq Posted August 1, 2007 Share Posted August 1, 2007 Assuming your form uses the POST method.... <?php $db = mysql_connect("localhost","root"); mysql_select_db("my_db",$db); $firstname = mysql_real_escape_string($_POST['firstname']); $query="SELECT age FROM person WHERE firstname='$firstname'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); list($fieldname,$fieldvalue) = each($record); echo $fieldvalue; } else { echo "No results found for $firstname<br />"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$query"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62825-another-help-please/#findComment-312783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.