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. Quote Link to comment 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? Quote Link to comment 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] Quote Link to comment 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] Quote Link to comment 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] => mrfg2006@gmail.com [email] => mrfg2006@gmail.com [2] => matthew [password] => matthew [3] => 999 [ money] => 999 [4] => 0 [stars] => 0 ) Matt mrfgs2006@gmail.comWhen I would like the response: Matt 999 mrfgs2006@gmail.com (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? Quote Link to comment 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. Quote Link to comment 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 ;) Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Removed. Fixed. Quote Link to comment 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.