Jump to content

[SOLVED] mysql_num_rows unsupplied argument?


Foser

Recommended Posts

<?php // Includes!
require_once('includes/mysql.php');
session_start();?>
<?php
if (isset($_POST['login_submit'])){
$login_username = mysql_real_escape_string($_POST['login_user']);
$login_pw = md5($_POST['login_pass']);
$check_query = mysql_query("SELECT * FROM user_info WHERE username = {$login_username} and WHERE password = {$login_pw}");

if (mysql_num_rows($check_query) > 0){  //Line 9!
$find_info = mysql_fetch_assoc($check_query);
$_SESSION['LOGGEDIN'] = TRUE;
$_SESSION['USERNAME'] = $find_info['username'];
$_SESSION['EMAIL'] = $find_info['email'];
echo "You are now Logged in as {$_SESSION[username]}.";
}
else {
echo "You have entered false data";}
}
?>

 

error message:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\PP\itemprogram\index.php on line 9

Link to comment
Share on other sites

Change:

$check_query = mysql_query("SELECT * FROM user_info WHERE username = {$login_username} and WHERE password = {$login_pw}");

 

to:

$check_query = mysql_query("SELECT * FROM user_info WHERE username = {$login_username} and password = {$login_pw}");

 

Mind you, the better way to do it is as below so you get to see just what the problem is:

 

$query = "SELECT * FROM user_info WHERE username = {$login_username} and password = {$login_pw}";
$check_query = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

Link to comment
Share on other sites

Try changing this:

 

$check_query = mysql_query("SELECT * FROM user_info WHERE username = {$login_username} and WHERE password = {$login_pw}");

 

To this:

 

$sql = "SELECT * FROM user_info WHERE username = '" . $login_username . "' AND password = '" . $login_pw . "'";
$check_query = mysql_query($sql);
if (!$check_query){
   echo "Failed to execute query ($sql): " . mysql_error();
}

 

Regards

Huggie

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.