为什么这个if语句将用户重定向到下一个网页

时间:2013-11-06 21:05:37

标签: php if-statement header

我希望用户在单击提交按钮后继续进入下一页,而是在此页面加载时将其重定向到下一页。此代码也在标题上方的“else”语句中给出了错误。

<center>

<?php
        include "functions.inc";
        $datafile = "users.dat";
        if (array_key_exists('submit', $_POST))
// Function to check the password length
            {
            $the_user = $_POST['newuser'];
            var_dump($the_user);

            $users = arrayfile_to_array($datafile);
            // Validate user name and password

            // If valid, save to the file of users
            $users[] = $the_user;
            array_to_arrayfile($users, $datafile);
            }
            else
            {
            if (!file_exists($datafile))  // Data file doesn't exist, so create it
            {
                $users = array();
        array_to_arrayfile($users, $datafile);
            }
            else 
            {
                $users = arrayfile_to_array($datafile);
            }
            else
            {
            if (array_key_exists('submit', $_POST))     
            {
            header('Location: 04invoice.php');
            }
            }








?>
  <form name="<?php $_SERVER["PHP_SELF"] ?>" method="post"> 
      Username: <input type="text" name="newuser[username]">
      <br>Password: <input type="text" name="newuser[password]">
      <br>Confirm Password: <input type="text" name="newuser[confirm_password]">    
          <br>Email: <input type="text" name="newuser[mail]">


      </select><br> <input type="submit" name="submit" value="Sign Up"> 
  </form>

</center>

1 个答案:

答案 0 :(得分:0)

你有另外两个在语义上毫无意义且语法无效的方式:

        if (!file_exists($datafile))  // Data file doesn't exist, so create it
        {
            $users = array();
    array_to_arrayfile($users, $datafile);
        }
        else 
        {
            $users = arrayfile_to_array($datafile);
        } //HERE -------------------------------------------
        else
        {
        if (array_key_exists('submit', $_POST))     
        {
        header('Location: 04invoice.php');
        }
        }

“其他”应该做什么?

我还建议您正确缩进代码;它将使您更容易看到逻辑的哪些部分相互对应。