hoponhiggo Posted July 29, 2011 Share Posted July 29, 2011 Hi I am trying to develop an editprofile.php page to allow users to change their details. So far i have written <?php $result = mysql_query("SELECT username FROM users WHERE username = {$_SESSION['MM_Username']}"); $num_rows = mysql_num_rows($result); if($num_rows > 0) { while ($row = mysql_fetch_array($result)) { $username = $row['username']; } } ?> and then tried to test it by using <div><?php echo $username ?></div> but nothing is being echo'ed out. What am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/243176-help-with-edit-profile/ Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2011 Share Posted July 29, 2011 You could test with simple echop inside your IF, if the mysql query actually returned something. Set or die(mysql_error()) after your query to see if it gives any errors. Also before echoing the $username variable you could do var_dump($username); to see if that variable has anything inside it. Quote Link to comment https://forums.phpfreaks.com/topic/243176-help-with-edit-profile/#findComment-1248980 Share on other sites More sharing options...
WebStyles Posted July 29, 2011 Share Posted July 29, 2011 does $_SESSION['MM_Username'] exist and have a value that exists in the database? Your entire script will do exatly the same as this: $username = $_SESSION['MM_Username']; Quote Link to comment https://forums.phpfreaks.com/topic/243176-help-with-edit-profile/#findComment-1248981 Share on other sites More sharing options...
hoponhiggo Posted July 29, 2011 Author Share Posted July 29, 2011 Dam. Another rookie mistake. I could have just echo'd $_SESSION['MM_Username'] couldnt i? Silly me Quote Link to comment https://forums.phpfreaks.com/topic/243176-help-with-edit-profile/#findComment-1248989 Share on other sites More sharing options...
Adam Posted August 24, 2011 Share Posted August 24, 2011 While yes you could simply have echoed the session variable, you will later still need to retrieve the rest of the details for the user to see and edit. So you need to add the error / empty result set checks, and alter your query to return more of the columns. Quote Link to comment https://forums.phpfreaks.com/topic/243176-help-with-edit-profile/#findComment-1261366 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.