Jump to content

Just a small query problem. Easy one!


McMaster

Recommended Posts

Hi,

 

I am having a slight issue with a mysql query. I am getting the following error:

 

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ***

 

$sql = "SELECT * FROM inbox WHERE product_id = '".$_GET['id']."' AND from != 'admin'";

$res = mysql_query($sql);

$row = mysql_fetch_assoc($res);

 

Now you see, if I take away the 'from' part of the query I don't get this error. Is there any way to stop this error without having to change the from field in my database table?

 

Thanks guys!

Link to comment
https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/
Share on other sites

THe problem is that "from" is a keyword in mySQL. To stop the problem, surround from in backticks ``

 

$sql = "SELECT * FROM inbox WHERE product_id = '".$_GET['id']."' AND `from` != 'admin'";

 

This removed the error I was getting but the query still isn't working right :( Hmmm!

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.