I would like to have some php code detect if a user exists in a database or not, and execute specific code according to the condition. This is what I have tried:
$query = "SELECT * FROM users WHERE
username='$username'
OR email='$email'
LIMIT 1";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
if(count($row) > 0) {
echo "The user exists";
} else {
echo "The user does not exist";
}
}
It echos "The user exists" when the user exists but not "the user does not exist" when the user doesn't exist. Why is this?