Page 1 of 1
mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 3:04 pm
by rashawn116
wut does this ->Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/38/5225538/html/browneyes2/login.php on line 21
error mean please can someone help me with this
the code that i use for this is
Code: Select all
$query="SELECT * USERS WHERE username= '%s' AND password'%f' ";
$login=sprintf($query, mysql_real_escape_string($username),mysql_real_escape_string($password));
$count = mysqli_num_rows(mysql_query($login));
and i get that error can someone please help
Re: mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 3:35 pm
by Christopher
$query="SELECT * FROM USERS WHERE username= '%s' AND password'%f' ";
It is a good practice to return the result of a query to a variable and check for an error before using the result. The error message would have helped you find this error.
Re: mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 3:40 pm
by rashawn116
thanks ur a life saver i wish eclipse had a sql de bugger
Re: mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 3:54 pm
by AbraCadaver
rashawn116 wrote:thanks ur a life saver i wish eclipse had a sql de bugger
Code: Select all
$result = mysql_query($login) or die(mysql_error());
Re: mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 4:39 pm
by Christopher
AbraCadaver wrote:Code: Select all
$result = mysql_query($login) or die(mysql_error());
I don't think die() is a very good practice. I would rather see:
Code: Select all
$sql = "SELECT * FROM users WHERE username= '%s' AND password'%f' ";
$sql = sprintf($sql, mysql_real_escape_string($username),mysql_real_escape_string($password));
$result = mysql_query($login);
if (mysql_errno($login) == 0) {
$count = mysql_num_rows($result);
// show the success response
} else {
$errmsg = mysql_error($login);
// show the error response
}
Re: mysql_num_rows help please help!!!!!!
Posted: Sat Jan 30, 2010 5:50 pm
by rashawn116
yea me either i would include a file to reply with the error message