Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Function no longer working / wont check if email already exists

$
0
0

Hey freaks,

 

i have been working on a log in / register system for a couple days now, and i am in the process of finalizing my end users activation of a newly registered account.

 

I was having no real issues until now, to where i am utterly confused as to why i am having such a core problem.

 

So for the first part i had a user register, and wanted to make sure the user is not already entering an email that already exists in my Database.

 

 

if (email_exists($_POST['register_email']) === true) {
$errors[] = 'The email you provided is already in use. If you are having trouble remembering your user info click <a href="#">here</a>';
}

the error goes to an errors array i have setup with all the errors that would display to the end user if any occur.

 

the email_exists() is the following :

function email_exists($email) {


$username = sanitize($email);
$query = (" SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' ");
$results = mysql_query($query);


if(mysql_error()) {
echo 'MySQL Error: '. mysql_error() .'<br>';
echo 'Query: '.$query;
}  else if(!mysql_num_rows($results)) {
//###  row has not been returned 
}  else {
//### row has been returned
}


return (mysql_result($results, 0) == 1) ? true : false;
}
 

 

Now everything in the function calls correctly, and as you see in the error check, row will be returned.

 

Yet, as you see in my IF statement in the error check above, nothing is being returned with the variable i am inputting ( yet the other IF statement all seem to work with the same variable $_POST)

 

now this i figured was the problem to my MAIN and number one issue. Getting my user activation working.

 

if(isset($_GET['success']) === true && empty($_GET['success']) === true){ 
?>
<h2> Thank you, your account has been activated</h2>
<h3> You can now log in and access the site and join the disscussions in out forum !</h3>
<?
} else if (isset($_GET['email'], $_GET['email_code']) === true){ 
$email  =  trim($_GET['email']); 
$email_code = trim($_GET['email_code']);


if (email_exists($email) === false ){
$errors[] = ' We have a problem, we couldn\'t find that email address !'; // THIS IS THE ERROR GIVEN TO USER
} else if (activate($email, $email_code) === false) {
$errors[] = ' We had a problem activating your account ';
}
if(empty($errors) === false){
?>
<h2>Oops...</h2>
<?
echo output_errors($errors);
} else {
header('Location: activate.php?success');
exit();
}


} else {
header('Location:  index.php');
exit();
 }
 

Now above i have highlighted what conditional is passed, when a end user click on the return link to activate their account.

 

as i mentioned above , i know its the email_exists function, since not only does that conditional fail . in database i can create multiple users with the same email.

 

Please guys any help would be greatly appreciated. 

 

I am a PHP / Programming noob , but i am trying my best to debug and catch my issues. i just cant figure this one out on my own .

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles