我试图检查数据库中列出的电子邮件地址以确保它与任何电子邮件地址不匹配。试图检查数据库中是否已经存在电子邮件
我试图使用rowCount
,据我了解,它会返回bool 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.';
}
为什么不能对同一匹配的电子邮件一个在数据库中并抛出错误消息?
谢谢,但我只想使用pdo。 – crm
你可不可以这么说!我的吸引力中心是sql和结果逻辑..你可以根据你的需要编写它.. – manurajhada