I am trying to check an email address against ones listed in a database to make sure it doesn't match any.
I have attempted to use rowCount
which I understand returns a bool true
or false
on whether it found a match.
But the email address still gets entered into the database.
Here is the method I'm using to check the email:
public function checkEmail(){
if($this->post_data['reg_email'] == $this->post_data['reg_conf_email']){
if(filter_var($this->post_data['reg_email'], FILTER_VALIDATE_EMAIL)){
$stmt = $this->dbh->prepare("SELECT email FROM oopforum_users WHERE email = ?");
$stmt->bindParam(1, $this->post_data['reg_email'], PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->rowCount();
if($this->result){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}
Then in my calling program I have this:
if($register->checkUsername()){
if(!$register->checkEmail()){
//continue...
}else{
$message = 'ERROR: That email is not valid, doesn\'t match the confirmation email or already exists on our database, please choose another one.';
}
}else{
$message = 'ERROR: That username is invalid or is already taken, please choose another one and ensure it is atleast 4 characters long.';
}
Why is it not matching the email against the same one in the database and throwing the error message?