0

我想让用户在单击提交按钮后继续进入下一页,而是在加载此页面时将用户重定向到下一页。此外,这段代码在标题上方的“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>
4

1 回答 1

0

您有两个 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);
        } //HERE -------------------------------------------
        else
        {
        if (array_key_exists('submit', $_POST))     
        {
        header('Location: 04invoice.php');
        }
        }

“其他”应该做什么?

我还建议正确缩进您的代码;这将使您更容易查看逻辑的哪些部分彼此对应。

于 2013-11-06T21:11:38.270 回答