mysql_num_rows help please help!!!!!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rashawn116
Forum Newbie
Posts: 5
Joined: Wed Aug 12, 2009 3:43 am

mysql_num_rows help please help!!!!!!

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mysql_num_rows help please help!!!!!!

Post 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.
(#10850)
rashawn116
Forum Newbie
Posts: 5
Joined: Wed Aug 12, 2009 3:43 am

Re: mysql_num_rows help please help!!!!!!

Post by rashawn116 »

thanks ur a life saver i wish eclipse had a sql de bugger
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql_num_rows help please help!!!!!!

Post 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());
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mysql_num_rows help please help!!!!!!

Post 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
}
(#10850)
rashawn116
Forum Newbie
Posts: 5
Joined: Wed Aug 12, 2009 3:43 am

Re: mysql_num_rows help please help!!!!!!

Post by rashawn116 »

yea me either i would include a file to reply with the error message
Post Reply