将表单值从第一页传递到第4页

时间:2015-07-26 07:24:43

标签: php

  1. 我的第一个文件是signup.php,里面有表格。我需要将表单值传递给第4页,即createAccount.php。

    1. 在signup.php之后,我有一个与creaditCardInfo.php(第三个文件)文件链接的userAgreement.php(第二个文件)文件。最后,我有createAccount.php文件。
    2. 我需要帮助。我知道我可以在$ _session中存储表单值,但它不起作用。
    3. 你能帮我弄清楚错误在哪里吗?
    4. 下面是我的4个文件。

      <?php
      include 'preCode.php';
      include 'header.php';
      echo '<body><div class="standardLayout">';
      echo '<h2>Account Information</h2>';
      ?>
      <form method="post" action="userAgreement.php">
      <table>
      <tr><td>Email:</td><td><input type="text" name="email"></td></tr>
      <tr><td>First Name:</td><td><input type="text" name="fName"></td</tr>                   
      <tr><td><input type="submit" value="Create Account"></td></tr>
        </table>
         </form>
       <?php
       echo'</div>';
       include 'footer.html';
        ?>
      

      userAgreement.php(第2页)

         <?php
         include 'preCode.php';
         include 'header.php';
         echo '<body><div class="standardLayout">';
         include 'systemMenu.php';
           $_SESSION['email'] = secure_input($_POST['email']);
           $_SESSION['fName'] = secure_input($_POST['fName']);
           ?>
      

      creditCardInfo.php(第3页)

           <?php
              include 'preCode.php';
              include 'header.php';
               echo '<body><div class="standardLayout">';
               include 'systemMenu.php';
               $_SESSION['email'] = secure_input($_POST['email']);
               $_SESSION['fName'] = secure_input($_POST['fName']);
              ?>
      

      createAccount.php(第4页)

          <?php
           include 'preCode.php';
           include 'header.php';
           echo '<div class="standardLayout">';
           include 'systemMenu.php';
           $_SESSION['fName'] = secure_input($_POST['fName']);
           $_SESSION['email'] = secure_input($_POST['email']);
           $email = $_SESSION['email'];
           echo $email;
           $_SESSION['fromLogin'] = false;
           $user = new user();
           $user->fName = secure_input($_POST['fName']);
           $user->email = secure_input($_POST['email']);
           $query = "INSERT INTO Users (fName, email)VALUES ('" . $user->fName . "', '" . $user->email . "');
           echo '<h2>User Information</h2>
          <div class="left">
         <form method="post" action="editUser.php">
          // I want to display session values here in this form. But its not printing anything except the field names(Name and email).
        <i>Name:</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '$user->fName . '<br>
        <i>Address:</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'$user->address .'<br>
         <input type="submit" value="Edit Information"></form>';
      

1 个答案:

答案 0 :(得分:1)

最后一页(createAccount.php)似乎是问题所在。您可以根据表单提交为会话变量分配值,但是根据代码判断,没有表单提交到该页面。不是永久地分配这些变量,而是简单地使用存储的会话变量,而不是使用有效的空值重新分配。事实上,第3页也是如此 - 似乎没有一个表单发布到第3页,所以再一次用空值覆盖会话变量。当然,在包含的文件中可能有一个表单,但如果是这样的话,为什么还有另外一对字段&#39; email&#39;和&#39; fName&#39; ??

creditCardInfo.php(page 3)
--------------------------
 <?php
    include 'preCode.php';
    include 'header.php';
    echo '<body><div class="standardLayout">';
    include 'systemMenu.php';
 ?>

 createAccount.php(page 4)
 -------------------------
<?php
     include 'preCode.php';
     include 'header.php';
     echo '<div class="standardLayout">';
     include 'systemMenu.php';

     $email = $_SESSION['email'];
     $_SESSION['fromLogin'] = false;

     echo $email;

     $user = new user();
     $user->fName = $_SESSION['fName'];
     $user->email = $_SESSION['email'];
     $query = "INSERT INTO Users (fName, email)VALUES ('" . $user->fName . "', '" . $user->email . "');

     echo '
        <h2>User Information</h2>
        <div class="left">
        <form method="post" action="editUser.php">
            <i>Name:</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '.$user->fName . '<br>
            <i>Address:</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$user->address .'<br>
            <input type="submit" value="Edit Information">
        </form>';
?>