-5

Possible Duplicate:
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource

Im getting this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u391124286/public_html/options.php on line 7

My code is

<?php
$con=mysql_connect("localhost","root","pass"); 
mysql_select_db("my_db"); 
$query=mysql_query("SELECT * FROM Options where
Option='Map' AND 
Toggle='1'"); 
$count=mysql_num_rows($query);
if($count==1){ 
$Map='1';
}
else
{
$Map='0';
}

?>

i dont understand why this error is occuring, i am fairly new to php so it is probably something simple.

Community
  • 1
  • 1
  • Do the query succeed? It's common to add `or die(mysql_error())` after each `mysql_query` call to catch these types of errors. – Emil Vikström Jun 03 '12 at 10:04
  • this happens if your query has an error. Then the query result ($query) is an "invalid result". – Stefan Fandler Jun 03 '12 at 10:05
  • 4
    please stop writing new code with the ancient `mysql_*` functions. They are no longer maintained and community has begun the [deprecation process](http://goo.gl/KJveJ) . Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you cannot decide, [this article](http://goo.gl/3gqF9) will help to choose. If you care to learn, [here is a quite good PDO-related tutorial](http://goo.gl/vFWnC). – Esailija Jun 03 '12 at 10:20

2 Answers2

0

PHP errors are sometimes pretty vague, see if you can get a better error message (and to check the query works) by entering the full query into the SQL tab in PHP My Admin.

ChrisBratherton
  • 1,540
  • 6
  • 26
  • 63
  • The OP would simply need to look for actual error messages, PHP can produce detailed errors when asked for. – deceze Jun 03 '12 at 10:24
0

After further investigation the field name you have used "Option" is a reserved word in SQL which means that you are unable to use. Here is a full list of SQL reserved words: http://developer.mimer.se/validator/sql-reserved-words.tml .

ChrisBratherton
  • 1,540
  • 6
  • 26
  • 63