Jump to content
xisto Community
Feelay

Warning: Mysql_num_rows() What is the error :S

Recommended Posts

Hey!
I've made a register script.. Some time ago it worked. And I ain't sure if I changed something since then..
The error I am getting is this:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31




Here is the code on theese lines:

$sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";				if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )		{			$sqlRegUser = 	"INSERT INTO						user( username, password )					VALUES(						'". $username ."',						'". $password ."'						)";			if( !mysql_query( $sqlRegUser ) )			{				$feedback[] = 'You Could Not Register Because Of An Unexpected Error.';			}

Any Idea What I've made wrong. And maybe anyone can tell me when mysql_num_rows errors occure.

Thank You For You're Help

//Feelay

Share this post


Link to post
Share on other sites

Hey!I've made a register script.. Some time ago it worked. And I ain't sure if I changed something since then..
The error I am getting is this:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31
Here is the code on theese lines:

$sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";				if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )		{			$sqlRegUser = 	"INSERT INTO						user( username, password )					VALUES(						'". $username ."',						'". $password ."'						)";			if( !mysql_query( $sqlRegUser ) )			{				$feedback[] = 'You Could Not Register Because Of An Unexpected Error.';			}

Any Idea What I've made wrong. And maybe anyone can tell me when mysql_num_rows errors occure.

Thank You For You're Help

//Feelay
You got that error because your query returns FALSE and the mysql_num_rows() function expects a valid result set, in this case it means that it is a new user and is valid to register, to work, try this code instead:

<?php$sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";$result = mysql_query($sqlCheckForDuplicate) or die(mysql_error());if(mysql_num_rows($result)>0){	$feedback[] = 'You Could Not Register Because the User already exists.';}else{	$sqlRegUser = "INSERT INTO user(username, password) VALUES('$username','$password')";	if(!mysql_query($sqlRegUser))	{		$feedback[] = 'You Could Not Register Because Of An Unexpected Error.';	}}?>
Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.