mysql_num_rows Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brmcdani44
Forum Commoner
Posts: 26
Joined: Fri Oct 08, 2010 3:52 pm

mysql_num_rows Error

Post by brmcdani44 »

I keep getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

On this line of code:
$verifynotregistered = mysql_num_rows($sql2) or die(mysql_error());

Can someone please give me a hand. Thanks in advance!

Attached is the code block:

Code: Select all

$activationKey =  mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$firstname = mysql_real_escape_string($_POST[firstname]);
$lastname = mysql_real_escape_string($_POST[lastname]);
$username = mysql_real_escape_string($_POST[username]);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST[email]);
$sql="INSERT INTO users (firstname,lastname,username, password, email, activationkey, status) VALUES ('$firstname', '$lastname', '$username', '$password', '$email', '$activationKey', 'verify')";
$sql2="Select * from users WHERE email='$email'";
$verifynotregistered = mysql_num_rows($sql2) or die(mysql_error());
if ($verifynotregistered == 1)
{
echo "You have already registered,Click here to recover your password";
}
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: mysql_num_rows Error

Post by anantha »

you should not pass the sql query...you may do like this

$result=mysql_query($sql2);

then pass the $result to mysql_num_rows($result);

this should work...
tomindo
Forum Newbie
Posts: 13
Joined: Sun Mar 21, 2010 1:22 am

Re: mysql_num_rows Error

Post by tomindo »

you need to fix sql2 like this

Code: Select all

$sql2="Select * from users WHERE email='".$email."'";
brmcdani44
Forum Commoner
Posts: 26
Joined: Fri Oct 08, 2010 3:52 pm

Re: mysql_num_rows Error

Post by brmcdani44 »

Now I am getting this error

Call to undefined function mysql_qry()

Hmmm
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mysql_num_rows Error

Post by Darhazer »

brmcdani44 wrote:Now I am getting this error

Call to undefined function mysql_qry()

Hmmm
It's really obvious :) There is no function mysql_qry()
The function is mysql_query()
brmcdani44
Forum Commoner
Posts: 26
Joined: Fri Oct 08, 2010 3:52 pm

Re: mysql_num_rows Error

Post by brmcdani44 »

Yeah I fixed it 2 seconds after I posted that
lol
Post Reply