You need to check that $result
is valid before calling mysql_num_rows()
(ie usually immediately after mysql_query()
, otherwise you can get this error.
However, if $result
isn't a valid resource, then it means that your query failed, so the problem is earlier than mysql_num_rows()
.
I note that you're using @
to supress any errors thrown by mysql_query()
. Why are you doing this? If you're getting an error from it, you need to (a) know about it, and (b) fix it. An error there implies that your SQL query has bugs - you should investigate this before anything else, as this is where your real problem lies.
You can find out what error was thrown by mysql_query()
by using the mysql_error()
function. It will tell you what the problem is with the query. (at first glance the query looks okay, but you could easily have mis-spelled a field name, or got a field in the wrong table prefix, etc; you'd need to see the error response to know for sure what the problem is)
By the way, is_numeric
is not a good check for whether the input is valid or not: it can return true for values which will fail in your query (eg numbers in scientific exponential format, decimal values, etc).