简体   繁体   English

注册表:电子邮件检查问题

[英]Registration form: problems with email check

i have a problem with the realization of a registration form. 我对注册表的实现有疑问。 My php script should check if the user email is already in use. 我的php脚本应检查用户电子邮件是否已被使用。 if the email is in use the php script should show an error message, if it is not the registration is successfully completed. 如果电子邮件正在使用中,则php脚本应显示一条错误消息,如果不是,则注册成功完成。

$email = $_POST['email'];       
  try{            
        $sql = "SELECT count(mail) FROM user WHERE mail = '$email'";            
        $result = $pdo->exec($sql);        
  }catch(PDOException $e){            
      echo $e;            
      exit();        }
  if($result == 0){            
     //registration complete        }
  else{            
      //email already in use        } 

my problem is that i obtain always 0 as result also if the email is already inside the database. 我的问题是,即使电子邮件已经在数据库中,我也总是获得0。 But if i execute that sql code inside my xampp' server i obtain 1 so the code works perfectly. 但是,如果我在xampp服务器中执行该sql代码,我将获得1,因此该代码可以完美运行。

Thank you to all for help :) 谢谢大家的帮助:)

You need to do this: 您需要这样做:

$email = $_POST['email'];       
  try{            
        $sql = "SELECT mail FROM user WHERE mail = :email";   
        $sql = $pdo->prepare($sql);
        $sql->execute(array(':email'=> $email));       
  }catch(PDOException $e){            
      echo $e;            
      exit();        }
  if($sql->rowCount() == 0){            
     //registration complete        }
  else{            
      //email already in use        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM