McMaster Posted April 26, 2010 Share Posted April 26, 2010 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 More sharing options...
taquitosensei Posted April 26, 2010 Share Posted April 26, 2010 if this $sql = "SELECT * FROM inbox WHERE product_id = '".$_GET['id']."' AND from != 'admin'"; works Then so should this $sql = "SELECT * FROM inbox WHERE product_id = '".$_GET['id']."'"; Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048475 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 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'"; Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048477 Share on other sites More sharing options...
McMaster Posted April 26, 2010 Author Share Posted April 26, 2010 I know what you are saying but I really need to have it so it doesn't show the admin part. Is there anything I can do with the from field to make this work? Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048478 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 Oh, if you don't know where the back tick key is, it should be just below Escape. Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048479 Share on other sites More sharing options...
McMaster Posted April 26, 2010 Author Share Posted April 26, 2010 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! Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048482 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 How is the query not working? Is it displaying admin entries? Or none at all? Link to comment https://forums.phpfreaks.com/topic/199762-just-a-small-query-problem-easy-one/#findComment-1048483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.