wat does this mean

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rashawn116
Forum Newbie
Posts: 5
Joined: Wed Aug 12, 2009 3:43 am

wat does this mean

Post 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>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: wat does this mean

Post 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.
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: wat does this mean

Post 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()!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: wat does this mean

Post 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.
Post Reply