Jump to content

wrong mysql value/column being selected.


mattal999

Recommended Posts

hi,

 

my mysql connects to the db fine and then selects the right row. Then when it gets to echo section, it prints the first column/value which is ID. Heres mysql table structure.

 

ID                   USERNAME                    PASSWORD                   EMAIL                RACE            HEALTH <----- this is one i want
1                    dsfasdfsdf               
2                    ..............                     
3
4
..

 

 

Here is the code for stats.php:

 

<?php

$host="sql2.ifastnet.com"; // Host name.
$db_user="::you can't know! XD::"; // MySQL username.
$db_password="::you can't know! XD::"; // MySQL password.
$database="rpgnow_"; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

$query = "SELECT * FROM rpgusers WHERE username =  '" . $_SESSION["username"] . "'";;
$result = mysql_query($query);
echo "<font color='ff0000' size='1' face='verdana'>Health = $result</font>";

?>

 

After i login as admin ( who has the user id of 3 =] )and click on status page link it says:

Health = Resource id #3

 

please help...

Link to comment
https://forums.phpfreaks.com/topic/39343-wrong-mysql-valuecolumn-being-selected/
Share on other sites

<?php
mysql_connect("host","user","password");
mysql_select_db("database");
$query = "SELECT * FROM rpgusers WHERE username =  '" . $_SESSION["username"] . "'";;
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "<font color='ff0000' size='1' face='verdana'>Health = $row['Health']</font>";
}
?>

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.