I'm putting together an email activation page for my site and having issues. It seems that despite the page receiving all the needed info to show the successful activation message, it randomly decides to show the error message stating that the credentials did not match anything in the database. here's the code
// Check their credentials against the database
try {
$check = $db->prepare("SELECT * FROM users WHERE id= ? AND username = ? AND email = ? AND user_ident = ? AND activated = '1' AND email_activated = '0' LIMIT 1");
$check->bindParam(1, $id);
$check->bindParam(2, $u);
$check->bindParam(3, $e);
$check->bindParam(4, $p);
$check->execute();
$num_rows = $check->rowCount();
} catch(Exception $er){
// ERROR : COULD NOT INSERT EMAIL INTO USERS TABLE
Send_email('support@site.com', 'check user - email activation failure', 'Could not check user '.$er);
exit;
}
// Evaluate for a match in the system (0 = no match, 1 = match)
if($num_rows === 0){
Send_email('support@site.com', 'email activation credentials no match', 'invalid email activation variables.<br/> email: '.$e.'<br/>userid: '.$id.'<br/>username: '.$u.'<br/>user_ident: '.$p);
header("location: message.php?msg=Your credentials are not matching anything in our system");
exit();
}
// Match was found, you can activate them
try {
$checking = $db->prepare("UPDATE users SET email_activated = 1 WHERE id= ? LIMIT 1");
$checking->bindParam(1, $id);
$checking->execute();
} catch (Exception $er){
// ERROR : COULD NOT INSERT EMAIL INTO USERS TABLE
Send_email('support@site.com', 'Email add error', 'Could not set active state '.$er);
exit;
}
So sometimes, when clicking on the activation link in the email it will work fine, then other times it will throw up the error saying that the credentials do not match anything in the database HOWEVER when i check the database immediately after clicking the link, the email_activated field has been updated to show that it's been activated. This technically shouldn't be occurring as, if i'm doing this correctly, the page will exit after throwing up the credentials error, meaning the email_activated update code should never even run. It seems like it might be running twice but i've used a counter and that's only showing one run. any help would be great!