Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Server Side Coding
MySQL

Why do I get a 'Supplied argument is not a valid MySQL result resource' error? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5673" title="Pages that link to Why do I get a &amp;#039;Supplied argument is not a valid MySQL result resource&amp;#039; error?" rel="nofollow" >Why do I get a &#039;Supplied argument is not a valid MySQL result resource&#039; error?\

There are a number of possible solutions (which are largely connected with the preceeding SQL statement rather than anything on the line the error number is for (mysql_num_rows() is commonly indicated if it is being used):

1. Make sure the tables and fields exist in your SQL statement.

2. If you are passing a variable in the SQL make sure it is probably escaped (usally in single quotes, but don't forget to addslash() if it came from outside (ie. get/post/cookie) and magic_quotes_gpc is off. Look those up in the php manual if you don't know what they mean).
Not doing this will generate the error:

code:
$sql = "SELECT something
FROM table
WHERE something = $variable";



and this will fix things:

code:
$sql = "SELECT something
FROM table
WHERE something = '$variable'";



Note: you could also use double quotes, but not within a double quoted string...

---------------------------
Relevant links:

PHP/MySQL error

Minor mySQL troubles (in PHP)

_____________________
Emperor

(Edited by: Tyberius Prime on Mon 12-May-2003)

« BackwardsOnwards »

Show Forum Drop Down Menu