mysql_num_rows() error

Hi all,

I have a registration page for users to make an account on my website. The code I have problems with is to make sure someone doesn’t try to use a username that has already been used.

I’m currently getting the error - “mysql_num_rows() expects parameter 1 to be resource, object given in C:\xampp\htdocs\motorstore\register.php on line 87”

my code:
[php]
$username = $_POST[“username”];
$username = mysqli_real_escape_string($custdb, $username);
if (isset($_POST[‘username’]))
{

		if (mysql_num_rows(mysqli_query($custdb, "SELECT * FROM customer WHERE username='$username'")))
			echo "Name is taken, please try a different name";
	}

[/php]

Any help is great, thanks!
Jack

If you place a Unique constraint on the column in the table, you would only have to watch for a specific error code.

Instead, you are nesting a query where it shouldn’t be, causing your issue.

You can’t mix mysql with mysqli.

Thanks [member=72272]astonecipher[/member] - I removed the mysql part of the query and it works.

Thanks [member=46186]Kevin Rubio[/member] - I didn’t realise I’d put mysql instead of mysqli!

Thanks again!

Sponsor our Newsletter | Privacy Policy | Terms of Service