Jump to content

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


Jragon

Recommended Posts

Hey,

 

When i atemt to tun this srcipt i get an error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\visualupload\login.php on line 17

 

My code:

<?php
include("getsalt.php");
require("connect.php");

$post_username = $_POST['user'];
$post_password = $_POST['pass'];

if (isset($post_password) && isset($post_username)){
    if(strlen($post_username)>25||strlen($post_password)>25){
        die('Username or password character length too long!');
    }else{
        //convert pass to md5
        $salt = getsalt($post_username);
        $post_password = md5($salt.$post_password);

        $login = sprintf('SELECT * FROM user WHERE username=`%s` AND password = `%s`', mysql_real_escape_string($post_username), mysql_real_escape_string($post_password));
        $rowcount = mysql_num_rows(mysql_query($login));
        echo $rowcount;
        if ($rowcount == 1){
            $_SESSION['user'] = $post_username;
        }
    }
}else{
    die('Please enter a useranme and password');
}
?>

You're getting that error because mysql_query is returning boolean false as a result of your query failing.

 

You need to use quotes, not back ticks.

 

$login = sprintf("SELECT * FROM user WHERE username='%s' AND password = '%s'", mysql_real_escape_string($post_username), mysql_real_escape_string($post_password));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.