mysqli_num_rows()
can only be used with SELECT
queries, it returns the number of rows in the result set.
To test how many rows were affected by a modification query, use mysqli_affected_rows()
. And the argument to this should be $connect
, not $result
(which is just a boolean).
$result = mysqli_query($connect, $query);
if (!$result) {
die (mysqli_error($connect));
} elseif (mysqli_affected_rows($connect) == 0) {
exit ("Username already exists");
} else {
echo '<h3><font color="red">You have successfully registered</font></h3>';
}
solved How to check if username already registered