-1

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

return (mysql_result(mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `user_id` = $user_id AND `type` = 1"), 0) == 1) ? true :false;
Community
  • 1
  • 1
  • mysql_result(): supplied argument is not a valid MySQL result resource – user1560328 Jul 29 '12 at 00:30
  • There is an error in your query ($user_id is probably empty). – Vatev Jul 29 '12 at 00:31
  • There are literally thousands of questions about this. You have no error checking, and you're passing a faulty query directly to `mysql_result()`. Look at the "Related" section over to the right. – Michael Berkowski Jul 29 '12 at 00:32
  • Instead of nesting `mysql_query()` inside `mysql_result()`, store its resource in a variable and test if is `FALSE`. `echo mysql_error()` to see what the error is. – Michael Berkowski Jul 29 '12 at 00:35

1 Answers1

0

Try this:

<?php
$result = mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `user_id` = $user_id AND `type` = 1");

if (!$result) {
 die(mysql_error());
}

return (mysql_result($result, 0) == 1) ? true :false;

at least you will see the error.

Don't assume the query will always run ok, check for errors. Don't put everything in a single line, it makes the code too hard to read. Also: be sure to properly escape the input using mysql_real_escape_string in your case.

Also, check here

Community
  • 1
  • 1
Gabriel Sosa
  • 7,897
  • 4
  • 38
  • 48