I have a simple function below to check if the user is already registered on my site. If they are then it doesn't add them and if they aren't it adds them. However In my database for some weird reason a certain user is getting added multiple times with the exact same id. Is there something wrong with mysqli_num_rows?
$check = mysqli_query($con, "SELECT id FROM users WHERE id='$id'");
$row_cnt = mysqli_num_rows($check);
if ($row_cnt == 0) {
$query = "INSERT INTO users (id,username) VALUES ('$id','$username')";
mysqli_query($con, $query);
} else { // If Returned user . update the user record
$query = "UPDATE users SET username='$username' where id='$id'";
mysqli_query($con, $query);
}
$check? Show aprint_rorvar_dumpof$checkmysqli_store_result, what does it do? The docs formysqli_num_rows()don't show it being used?mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation to accomplish this because you will create severe SQL injection bugs.