Jump to content

PHP displaying database info


mattd8752

Recommended Posts

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]
<?php
session_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
Share on other sites

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]<?php
session_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
Share on other sites

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.com
When 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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.