我正在尝试根据数据库中列出的电子邮件地址检查电子邮件地址,以确保它不匹配。
我尝试使用rowCount
我理解的返回布尔值true
或false
是否找到匹配项。
但电子邮件地址仍会输入数据库。
这是我用来检查电子邮件的方法:
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;
}
}
然后在我的调用程序中我有这个:
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.';
}
为什么它不将电子邮件与数据库中的同一电子邮件匹配并抛出错误消息?