mattd8752 Posted January 21, 2007 Share Posted January 21, 2007 I've got my script here which should print out: [quote]matt 10000 [I am hiding my email here][/quote] but instead it prints out [quote]matt [I am hiding my email here][/quote] not including the money from the database.[code]<?phpsession_start();mysql_connect("localhost", "mattd_rpg", "myphprpg") or die("There was an error connecting to the mysql server.");mysql_select_db("mattd_rpg");$username=$_SESSION['username'];$password=$_SESSION['password'];$result=mysql_query("SELECT * FROM accounts WHERE username='$username' AND password='$password'");if(mysql_num_rows($result) == 0){die("Sorry, you are not logged in, please login again to continue playing. If you just signed in your username and/or password may be incorrect");}else{//start geting values$query="select * from accounts";$rt=mysql_query($query);echo mysql_error();while($nt=mysql_fetch_array($rt)){if($nt[username] == $username){echo "$nt[username] $nt[money] $nt[email]<br>";}}$cash = $nt[money];//finish getting values}?>[/code]Does anyone have any idea how I could fix this? If so please reply. Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/ Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You're accessing variables in arrays wrong. Try this.print_r($nt);echo $nt['username'].' '.$nt['money'].' '.$nt['email'].' '.<br>';What shows now from the print_r? Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165201 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 That does help clean up my code, but it did read off with an error. Heres a properly spaced version of my code:[quote]Parse error: syntax error, unexpected $end in /home/mattd/public_html/racing/index2.php on line 27[/quote][code]<?phpsession_start();mysql_connect("localhost", "mattd_rpg", "myphprpg") or die("There was an error connecting to the mysql server.");mysql_select_db("mattd_rpg");$username=$_SESSION['username'];$password=$_SESSION['password'];$result=mysql_query("SELECT * FROM accounts WHERE username='$username' AND password='$password'"); if(mysql_num_rows($result) == 0){ die("Sorry, you are not logged in, please login again to continue playing. If you just signed in your username and/or password may be incorrect"); }else{ //start geting values $query="select * from accounts"; $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ if($nt[username] == $username){ print_r($nt); echo $nt['username'].' '.$nt['money'].' '.$nt['email'].' '.'; } } }$cash = $nt[money];//finish getting values?>[/code] Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165206 Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 I forgot to use the code tag, so my br tag got cut off. [code]echo $nt['username'].' '.$nt['money'].' '.$nt['email'].'<br>';[/code] Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165208 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Ok, thanks alot. I guess i didn't look over the code enough.Now I've got another problem. Sorry.I get the response:Array ( [0] => Matt [username] => Matt [1] => [email protected] [email] => [email protected] [2] => matthew [password] => matthew [3] => 999 [ money] => 999 [4] => 0 [stars] => 0 ) Matt [email protected]When I would like the response: Matt 999 [email protected] (I added a random letter to my email, but you get the idea). I see all that data when I look all the way through, could you help me? Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165210 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 I found the problem myself from that, [ money] was being displayed, I figured out that there was a space before money. Thanks for the help anyway. Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165212 Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You should probably fix that in your database, so that doesn't happen again ;) Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165213 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Removed. Fixed. Link to comment https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/#findComment-165218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.