PhP验证无法正常退出

时间:2012-11-10 16:26:09

标签: php html

我正在尝试理清我的验证,下面是我的代码,我已经尝试了很多东西,包括把它变成if else结构,但无论我用它测试什么总是返回没有电子邮件的错误,并且我不知道为什么。我甚至尝试从第一个删除exit; if,但仍然只显示没有电子邮件。

if(!$reg_username){

     $reg_error = "You have not entered a Username.";
      $_SESSION['error'] = $reg_error;
      header("Location: register.php");
      exit;
 }

 if (!$reg_email){

     $reg_error = "You have not entered an Email.";
      $_SESSION['error'] = $reg_error;
      header("Location: register.php");
      exit;

 }
 if (!$reg_password){

     $reg_error = "You have not entered a Password.";
      $_SESSION['error'] = $reg_error;
      header("Location: register.php");
      exit;
 }
 if (!$reg_password_1){

     $reg_error = "You have not entered your Verification Password.";
      $_SESSION['error'] = $reg_error;
      header("Location: register.php");
      exit;
 }

任何想法?

由于

编辑:这是代码的其余部分

$reg_username = $_POST['reg_username'];
     $reg_email = $_POST['reg_email'];
     $reg_password = $_POST['reg_password'];
     $reg_password_1 = $_POST['reg_password_1'];
     $reg_dob_day = $_POST['reg_dob_day'];
     $reg_dob_month = $_POST['reg_dob_month'];
     $reg_dob_year = $_POST['reg_dob_year'];


     include_once "connect_to_mysql.php";
     $reg_username_length = "";
     $reg_password_length = "";
     $reg_dob_day_length = "";
     $reg_dob_year_length = "";


     $reg_email = stripslashes($reg_email); 
     $reg_password = stripslashes($reg_password); 
     $reg_password_1 = stripslashes($reg_password_1); 
     $reg_dob_day = stripslashes($reg_dob_day); 
     $reg_dob_month = stripslashes($reg_dob_month); 
     $reg_dob_year = stripslashes($reg_dob_year); 

     $reg_email = strip_tags($email);
     $reg_password = strip_tags($password);
     $reg_password_1 = strip_tags($reg_password_1);
     $reg_dob_day = strip_tags($reg_dob_day); 
     $reg_dob_month = strip_tags($reg_dob_month); 
     $reg_dob_year = strip_tags($reg_dob_year);



     $reg_username = mysql_real_escape_string($reg_username);
     $reg_email = mysql_real_escape_string($reg_email);
     $reg_password = mysql_real_escape_string($reg_password);
     $reg_password_1 = mysql_real_escape_string($reg_password_1);
     $reg_dob_day = mysql_real_escape_string($reg_dob_day);
     $reg_dob_month = mysql_real_escape_string($reg_dob_month);
     $reg_dob_year = mysql_real_escape_string($reg_dob_year);


     if(!$reg_username){

         $reg_error = "You have not entered a Username.";
          $_SESSION['error'] = $reg_error;
          header("Location: register.php");
          exit;
     }

     if (!$reg_email){

         $reg_error = "You have not entered an Email.";
          $_SESSION['error'] = $reg_error;
          header("Location: register.php");
          exit;
     }
     if (!$reg_password){

         $reg_error = "You have not entered a Password.";
          $_SESSION['error'] = $reg_error;
          header("Location: register.php");
          exit;
     }
     if (!$reg_password_1){

         $reg_error = "You have not entered your Verification Password.";
          $_SESSION['error'] = $reg_error;
          header("Location: register.php");
          exit;
     }
     if ($reg_password != $reg_password_1){

         $reg_error = "Your Verification Passwords do no match.";
          $_SESSION['error'] = $reg_error;
          header("Location: register.php");
          exit;
     }

1 个答案:

答案 0 :(得分:2)

您的以下内容:

$reg_email = strip_tags($email);

应该是这样的:

$reg_email = strip_tags($reg_email);

您似乎只是错误输入变量名称。