dongyan5141 2017-07-27 06:10
浏览 38

PHP会话及其在互连页面中的使用也是页面重定向

I have a question . This is the scope of the question :

Prepare a registration form on php and while submiting the data it will go to next page .Give link to a third page and Use sessions to print the collected data on this page.

I'm new to it so not really sure how to continue but I have prepared a form .It is as follows

      <!DOCTYPE HTML>  
       <html>
       <head>

      </head>
       <body> 
       <h2> Form  Example</h2>

       <form method="post" action="">  
      Name: <input type="text" name="name" value="">

       <br><br>
      Address: <input type="text" name="address" value="">

       <br><br>
       Comment: <textarea name="comment" rows="5" cols="40"></textarea>
      <br><br>
       Gender:
     <input type="radio" name="gender"  value="female">Female
     <input type="radio" name="gender"  value="male">Male

    <br><br>
    <input type="submit" name="submit" value="Submit">  
  </form>
     </body>
    </html>

Kindly guide me on how to continue further

  • 写回答

1条回答 默认 最新

  • dongxi4235 2017-07-27 06:29
    关注

    Use session variable for this.

     <!DOCTYPE HTML>  
       <html>
       <head>
    
      </head>
       <body> 
       <h2> Form  Example</h2>
    
       //add the redirect page
       <form method="post" action="redirect_page.php">  
      Name: <input type="text" name="name" value="">
    
       <br><br>
      Address: <input type="text" name="address" value="">
    
       <br><br>
       Comment: <textarea name="comment" rows="5" cols="40"></textarea>
      <br><br>
       Gender:
     <input type="radio" name="gender"  value="female">Female
     <input type="radio" name="gender"  value="male">Male
    
    <br><br>
    <input type="submit" name="submit" value="Submit">  
     </form>
     </body>
    </html>
    

    the redirect_page.php in the action should have the following code.

    <?php session_start();
    
    //submitted button created session variabale
    if( $_SERVER['REQUEST_METHOD'] == 'POST' )
    {
        $_SESSION['submit']['name'] = $_POST['name'];
    
        $_SESSION['submit']['comment'] = $_POST['comment'];
    
        $_SESSION['submit']['gender'] = $_POST['gender'];
    }
    
    foreach ($_SESSION['submit'] as $key => $value)
    {
        echo $key. ' = ' .$value.'</br>';
    }
    ?>
    
    //third Page Link
    <a href ="thirdpage.php">Third Page</a>
    

    the third page named thirdpage.php need only to have the fowllowing code. Because session submit already exists thanks to redirect_page.php has create for us!

     <?php session_start();
        foreach ($_SESSION['submit'] as $key => $value)
        {
           echo $key. ' = ' .$value.'</br>';
        }
     ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败