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');
}
?>

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.