PHP密码电子邮件和密码确认表单错误信息打印

时间:2016-10-06 09:20:14

标签: php

关于电子邮件被使用两次,我遇到了问题。它不打印通知用户他已经使用了该电子邮件。我之前有它工作,但是在添加密码确认字段后它停止工作。我想要它做的是打印"电子邮件无效或已被采取。"当电子邮件再次注册时。



if ($count==0) {
   if ($_POST["password"] == $_POST["confirm_password"]) {
      $query = "INSERT INTO login(username,email,password) VALUES('$username','$email','$encrypt')";
      if ($dbConnect->query($query)) {
       $alert = "<div class='alert alert-success'>
          <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Registered successfully!
         </div>";
      }else {
       $alert = "<div class='alert alert-danger'>
          <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Error try again or contact web master!
         </div>";
      }

     } else {


      $alert = "<div class='alert alert-danger'>
         <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Email is invalid or already taken.</div>";

     }

   }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

您将电子邮件存在代码块放在if($count == 0)块中。它不应该存在。它将在其他块中。使用以下代码。

if ($count==0) 
{
   if ($_POST["password"] == $_POST["confirm_password"]) 
   {
      $query = "INSERT INTO login(username,email,password) VALUES('$username','$email','$encrypt')";

      if ($dbConnect->query($query)) 
      {
       $alert = "<div class='alert alert-success'>
          <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Registered successfully!
         </div>";
      }
      else 
      {
       $alert = "<div class='alert alert-danger'>
          <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Error try again or contact web master!
         </div>";
      }

    } 
}
else 
{
  $alert = "<div class='alert alert-danger'>
     <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Email is invalid or already taken.</div>";

}