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

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

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

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.