0

我正在尝试整理我的验证,下面是我的代码,我已经尝试了很多东西,包括将它变成一个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;
     }
4

1 回答 1

2

您的以下行:

$reg_email = strip_tags($email);

应该是这样的:

$reg_email = strip_tags($reg_email);

看来您只是输错了变量名。

于 2012-11-10T16:37:32.497 回答