Page 1 of 1

wat does this mean

Posted: Wed Aug 12, 2009 3:45 am
by rashawn116
i get this error code here is the sniipit of code

Code: Select all

<?
  $user="select * from users where username=".$_POST["user"]."";
  $fetch=mysql_query($user);
  $row1 = mysql_fetch_object($fetch);
    if($_SESSION["status"]){
    echo"<p>you are already logged in".$row1->name."</p>";
    }
    else{
    $_SESSION["status"]=false;
    echo"you are not signedup or logged in";
    echo"<p>register</p><a href=\"index.php?page_index=register&rid=".$random."\">signup</a>";
    }
  ?>
then i get this error <b>Warning</b>: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>C:\xampp\htdocs\repair\index.php</b> on line <b>42</b><br>

Re: wat does this mean

Posted: Wed Aug 12, 2009 4:17 am
by jayshields
Change your

Code: Select all

mysql_query()
call to

Code: Select all

mysql_query($query) or die(mysql_error())
to help you debug.

Re: wat does this mean

Posted: Wed Aug 12, 2009 4:23 am
by turbolemon
Have you created a connection to your database? If so, have you selected your database?

Code: Select all

$db = mysql_connect('localhost','username','password');
if(!$db) {
    trigger_error("Could not connect to MySQL database.", E_USER_ERROR);
};
mysql_select_db('mydb',$db);
Although the query function will use the last active connection, its good practice to pass them explicitly.

Code: Select all

$fetch=mysql_query($user,$db);
if ($fetch)
$row1 = mysql_fetch_object($fetch);
else trigger_error(mysql_error($db), E_USER_ERROR);
Notice I didn't use die()!

Re: wat does this mean

Posted: Wed Aug 12, 2009 7:07 am
by requinix
Syntax error in the SQL too.

Code: Select all

select * from users where username=".$_POST["user"]
mysql_error would have told you about that.