Computer Science Canada

mysql_fetch_assoc error

Author:  unknowngiver [ Sat Jun 17, 2006 7:32 pm ]
Post subject:  mysql_fetch_assoc error

hey
i am getting this error
code:


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\htdocs\Zubair\details.php on line 13
????
:S
i dont know how to fix it Sad
here is the code:
php:

<?php
$user = $_GET['user'];
$detailpass = $_GET['detailpass'];
$action = $_GET['action'];
$dbusername="zubair";
$dbpassword="";
$database= "z_game";
if ($detailpass == "aa") {
        mysql_connect(localhost, $dbusername, $dbpassword);
        @mysql_select_db($database) or die("Unable to select database");
        $sql = mysql_query("Select * From user where username = ".$user." LIMIT 1")  ;
       
        $get_row = mysql_fetch_assoc($sql);
       
                if ($action = "list"){
        echo $get_row['health'];
        echo "?";
        echo $get_row['money'];
        echo "?";
        echo $get_row['country'];
        echo "?";
        echo $get_row['level'];
        echo "?";
        } }
else {
echo "error\n";
}
?>

Author:  rdrake [ Sat Jun 17, 2006 8:05 pm ]
Post subject: 

You must put quotes around "localhost" in your script. Unless stored in a variable, you need those quotes.

Also, as I recall it's the following, without the spaces.
[syntax = "php"]
<?php
echo "This is PHP";
?>
[/syntax]
So you'd get:
php:

<?php
    echo "This is PHP";
?>

Author:  JackTruong [ Sun Jun 18, 2006 4:29 pm ]
Post subject: 

code:
$sql = mysql_query("Select * From user where username = ".$user." LIMIT 1")  ;


Maybe change that to:
code:
$sql = mysql_query("Select * From user where username = \"".$user."\" LIMIT 1")  ;


Unless username is of type int...


: