Need to use mysqli_num_rows to check data

I have a fairly simple assignment for a class where I have various pages, but one process page that adds a user to a database. If the user already exists, I need an error message to display. I have the username a a unique field, but I still have to check using msqli_num_rows and it isn’t working. I have this code, which is giving me a parse error on the first line:

$query=$connection,“Select * from users where username=mysqli_real_escape_string($connection,$_POST[“username”])”;
$result= mysqli_query($query);
$num=mysqli_num_rows($result);
if ($num > 0) {//Username already exist
$errormessage = $errormessage . “Username already exists!<br />” );
}

I have other error messages that work fine.

Any suggestions?

Thank you.

As always, if you aren’t very far along into this project switch to PDO. It’s much easier to work with.

Also, in the future, How Do I questions like this go in the main PHP forum. The PHP Applications forum is geared more towards application design theory, not specific code issues.

Sorry, I am new to this and didn’t mean to post in the wrong area. I mentioned this is for a class so we have to use msqli_num_rows. Unfortunately, I do not know what PDO is. I found a solution to my code, however, so no problem. Thank you for the feedback and I will try to be in the proper area next time.