Jump to content

mysql_num_rows question.


Dark57

Recommended Posts

Ok so I'm using

$sql = "SELECT COUNT(*) FROM mytable WHERE username = '$username'";
$result = mysql_query($sql);
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$number=mysql_num_rows($result);
if($number>0)
{
echo "Duplicate Username <br />";
$_SESSION['usernamefail']=1;
}

 

But I keep getting this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Silent Night Online\check_register.php  on line 51

 

Line 51 refers to $number=mysql_num_rows($result); in this case.  I'm not sure why it is returning a true/false statement if its supposed to be counting the matching rows of a username?

Link to comment
https://forums.phpfreaks.com/topic/199083-mysql_num_rows-question/
Share on other sites

$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$sql = "SELECT * FROM `mytable` WHERE username = '$username'";
$result = mysql_query($sql) or die(mysql_error());
$number = mysql_num_rows($result);
if($number > 0)
{
echo "Duplicate Username <br />";
$_SESSION['usernamefail']=1;
}

 

Try that and let me know what happens. By the way, make sure you're cleaning (escaping) the variable before the MYSQL_QUERY() part, just to be safe.

Ah, I feel retarded now. I guess its a good thing I posted the code here so you could point out that to me too.  I've been developing this on two different computers and this is a new database I'm working with. I forgot to run my create_db.php file before trying to use this file /facepalm

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.