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
https://forums.phpfreaks.com/topic/35028-php-displaying-database-info/
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]
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.