Frank74 Posted November 16, 2011 Share Posted November 16, 2011 Hello, I'm new on this forum and i have not seen the rules to post a code, so i will try to explain my best : I have learned the basics of php during the past few days and i have a php code that is supposed to read parameters in several fields of a Mysql database and to return those parameters as variables in an array. (well that's how i understand it... please correct me if i'm wrong) So here the code and the part that doesn't seem to work properly (colored in red) : //I have changed the following values which are confidential... $DBName = "MyDatabase"; $DBHostName = "MyMysqlServer"; $DBUserName = "MyUsername"; $DBPassword = "MyPassword"; $Table = "MyTable"; //The fields which are in MyTable : // MemberID SMALLINT // MemberName VARCHAR(20) // MemberPassword VARCHAR(20) // MemberEmailAddress VARCHAR(50) // MemberDateTimeInscription VARCHAR(19) //Reading member parameters echo"<br>Reading the parameters of a member."; echo"<br>Defining the parameters of the member to read."; $CurrentName = "Ashley"; $CurrentPassword = "65hl3y"; $CurrentEmailAddress = "Ashley@HisDomain.com"; echo"<br>Trying to start a connection with the Mysql server."; mysql_connect($DBHostName,$DBUserName,$DBPassword) OR DIE(mysql_error()); echo"<br>Selecting the table."; mysql_select_db($DBName) OR DIE(mysql_error()); echo"<br>Searching for the fields corresponding to the CurrentName."; $Query = "SELECT * FROM ".$Table." WHERE MemberName = '".$CurrentName."'"; $Result = mysql_query($Query) or die(mysql_error()); echo"<br>Returning the parameters stored in the fields."; while($Row = mysql_fetch_array($Result,MYSQL_ASSOC)){ /////This is the start of the part that does not seem to work properly. $MemberId = $row["MemberId"]; $MemberName = $row["MemberName"]; $MemberPassword = $row["MemberPassword"]; $MemberEmailAddress = $row["MemberEmailAddress"]; $MemberDateTimeInscription = $row["MemberDateTimeInscription"]; echo"<br>MemberId : ".$MemberId; echo"<br>MemberName : ".$MemberName; echo"<br>MemberPassword : ".$MemberPassword; echo"<br>MemberEmailAddress : ".$MemberEmailAddress; echo"<br>MemberDateTimeInscription : ".$MemberDateTimeInscription; /////This is the end of the part that does not seem to work properly. } echo"<br>Ending the connection with the Mysql server."; mysql_close(); All of echo are here for debug, i'm a beginner with php. This is what the php page shows : Reading the parameters of a member. Defining the parameters of the member to read. Trying to start a connection with the Mysql server. Selecting the table. Searching for the fields corresponding to the CurrentName. Returning the parameters stored in the fields. MemberId : MemberName : MemberPassword : MemberEmailAddress : MemberDateTimeInscription : Ending the connection with the Mysql server. I don't understand why the variables $MemberId, $MemberName, $MemberPassword, $MemberEmailAddress, $MemberDateTimeInscription are empty. Your advices are welcome, Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/251278-the-php-code-works-but-i-have-no-variables-returned/ Share on other sites More sharing options...
phporcaffeine Posted November 16, 2011 Share Posted November 16, 2011 Here is the issue: while($Row = mysql_fetch_array($Result,MYSQL_ASSOC)){ /////This is the start of the part that does not seem to work properly. $MemberId = $row["MemberId"]; Your result set is assigned to $Row, and your trying to echo out the elements of $row (notice the casing of the letter R). Quote Link to comment https://forums.phpfreaks.com/topic/251278-the-php-code-works-but-i-have-no-variables-returned/#findComment-1288811 Share on other sites More sharing options...
jcbones Posted November 17, 2011 Share Posted November 17, 2011 Huff has it right. You should be running with error reporting at max and display errors on. (this can be set in php.ini) Setting it at runtime (each script) place this block at the top of the script. error_reporting(-1); ini_set('display_errors',1); This would have told you that $row did not exist. PS. welcome to the forum, let us know if an answer given doesn't work, we always check back. Otherwise, solved button is on lower right. Quote Link to comment https://forums.phpfreaks.com/topic/251278-the-php-code-works-but-i-have-no-variables-returned/#findComment-1288831 Share on other sites More sharing options...
Frank74 Posted November 17, 2011 Author Share Posted November 17, 2011 Hi It was indeed the "r" of "$row" which should be Uppercase. I will remind this lesson thanks Setting it at runtime (each script) place this block at the top of the script. error_reporting(-1); ini_set('display_errors',1); This would have told you that $row did not exist. Thanks for the trick! Otherwise, solved button is on lower right. I have found the solved button on the lower left Quote Link to comment https://forums.phpfreaks.com/topic/251278-the-php-code-works-but-i-have-no-variables-returned/#findComment-1288890 Share on other sites More sharing options...
jcbones Posted November 18, 2011 Share Posted November 18, 2011 I may be backwards, it has been re-written since I have seen it. Quote Link to comment https://forums.phpfreaks.com/topic/251278-the-php-code-works-but-i-have-no-variables-returned/#findComment-1289155 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.