I am trying to create a function that is going to check if an user exists based on their email. After comparing the submitted email with the email entries in my database, I want to see if an user is legit or not. This is what I have coded so far:
function user_exists($email)
{
$email = mysql_real_escape_string($email);
$query = mysql_query("SELECT COUNT(`id`) FROM `imgit_users` WHERE `email`='$email'");
return (mysql_result($query, 0) <= 1) ? true : false;
}
And I used it like this:
if (user_exists($register_email) === true)
{
echo 'Fail';
$errors[] = 'The supplied email is already in use';
}
else
{
if (empty($errors))
{
$user_id = user_register($register_username, $register_email, $register_password);
$_SESSION['imgit_uid'] = $user_id;
echo 'Okay';
}
}
My script keeps returning Okay instead of Fail, even if I type in the same email everytime. Ideas?
Swap the <= to >=