master82 Posted September 5, 2006 Share Posted September 5, 2006 What is wrong with this code?[code]<?phpinclude("database.php");$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");if (!$userstable) { echo 'Could not run users query: ' . mysql_error(); exit;}$user = mysql_fetch_row($userstable);//testingecho $user[userid];echo $user[username];?> [/code] When I run it I donr get any errors, just a blank page ??? Link to comment https://forums.phpfreaks.com/topic/19754-blank-output-problem/ Share on other sites More sharing options...
zawadi Posted September 5, 2006 Share Posted September 5, 2006 try this:[quote]<?phpinclude("database.php");$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");if (!$userstable) { echo 'Could not run users query: ' . mysql_error(); exit;}$user = mysql_fetch_row($userstable);//testingecho $user[0];echo $user[1];?> [/quote]you may need to edit the numbers to match the colum number.Also RTFM [url=http://uk.php.net/manual/en/function.mysql-fetch-row.php]http://uk.php.net/manual/en/function.mysql-fetch-row.php[/url] Link to comment https://forums.phpfreaks.com/topic/19754-blank-output-problem/#findComment-86264 Share on other sites More sharing options...
master82 Posted September 5, 2006 Author Share Posted September 5, 2006 That works great!But is there a way I can assign the values using their fieldnames rather than a number?eg$user[username] (would show the username)rather than$user[1]is it possible? Link to comment https://forums.phpfreaks.com/topic/19754-blank-output-problem/#findComment-86265 Share on other sites More sharing options...
Unknown User Posted September 5, 2006 Share Posted September 5, 2006 Err, i'm sure i do that.Add [quote]seesion_start();[/quote] at the top.Then, if you want their username for example.[quote]$_SESSION['username'][/quote] Link to comment https://forums.phpfreaks.com/topic/19754-blank-output-problem/#findComment-86279 Share on other sites More sharing options...
zawadi Posted September 5, 2006 Share Posted September 5, 2006 [quote]Descriptionarray mysql_fetch_row ( resource result )Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.[/quote]to use mysql_fetch_objectthen use $user->username; Link to comment https://forums.phpfreaks.com/topic/19754-blank-output-problem/#findComment-86281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.