mysql_num_rows() expects parameter 1 to be resource, boolean

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roughneck86
Forum Newbie
Posts: 1
Joined: Tue Dec 22, 2009 6:54 am

mysql_num_rows() expects parameter 1 to be resource, boolean

Post by roughneck86 »

what's wrong with my codes??
it say's "mysql_num_rows() expects parameter 1 to be resource, boolean given"
-----------------
$log_username = $_POST['username'];
$log_password = $_POST['password'];

$sql_user_verify = "SELECT COUNT(*) FROM users WHERE username= '$log_username' AND password = '$log_password'";

$user_result = mysql_query($sql_user_verify,$conn);

if(mysql_num_rows($user_result) == 1) {
//login successfull
}
----------------

my plan is to crete login form and check it in database and verify it...
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: mysql_num_rows() expects parameter 1 to be resource, boolean

Post by MichaelR »

The mysql_query is failing, returning false. Check your database connection.

As an extra note, never place $_POST/$_GET/$_COOKIE etc. details directly into an SQL query (because magic_quotes should be turned off).

You should use this:

Code: Select all

 
  if (get_magic_quotes_gpc()) {
 
    $_POST['username'] = stripslashes($_POST['username']);
    $_POST['password'] = stripslashes($_POST['password']);
 
  }
 
  $log_username = mysql_real_escape_string($_POST['username']);
  $log_password = mysql_real_escape_string($_POST['password']);
 
...
 
Post Reply