doforumda Posted February 7, 2010 Share Posted February 7, 2010 hi i have a code. the problem with that is when i select all data from table and put only firstname and lastname in a variables it then says these errors Notice: Undefined variable: firstname in C:\wamp\www\folder\member.php on line 12 Notice: Undefined variable: lastname in C:\wamp\www\folder\member.php on line 12 Welcome, to the member page! my code is here <?php session_start(); include('dbConnect.php'); $getNames = mysql_query("SELECT * FROM basicinfo WHERE userid='$_SESSION[userid]'") or die(mysql_error()); while($names = mysql_fetch_assoc($getNames)) { $firstname = $names['firstname']; $lastname = $names['lastname']; } echo "Welcome, ".$firstname." ".$lastname." to the member page!"; ?> where am i making mistake? Link to comment https://forums.phpfreaks.com/topic/191233-need-help-in-mysql_fetch_assoc/ Share on other sites More sharing options...
jl5501 Posted February 7, 2010 Share Posted February 7, 2010 Are the database fields called firstname and lastname or are you getting any error from mysql_fetch_assoc? change this while($names = mysql_fetch_assoc($getNames)) { $firstname = $names['firstname']; $lastname = $names['lastname']; to this while($names = mysql_fetch_assoc($getNames)) { print_r($names); $firstname = $names['firstname']; $lastname = $names['lastname']; to see what you are getting Link to comment https://forums.phpfreaks.com/topic/191233-need-help-in-mysql_fetch_assoc/#findComment-1008298 Share on other sites More sharing options...
doforumda Posted February 7, 2010 Author Share Posted February 7, 2010 thanks for your reply. it is working now Link to comment https://forums.phpfreaks.com/topic/191233-need-help-in-mysql_fetch_assoc/#findComment-1008303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.