dongxing9219 2012-06-04 05:02
浏览 9
已采纳

在php中使用后退按钮

I am very new to the world of PHP . The problem that I am facing is with the use of back button . When I click on the back button from page2 to page1 the options which I had selected on page1 is not getting saved . So I need to select all the data once again in page1 . I am using sessions . The funny part is when I use a text box question on page 1 and submit its value to page 2 and then click on back button on page2 the data is being saved . Please take a look into this code I named this file as 1.php

<?php
  session_start();
?>
<html>
<body>
<form action="2.php" method="post">

Name<input type="text" name="name" value="<?php if(isset($_SESSION['name'])) echo $_SESSION['name']; ?>"/>


<input type="submit"  value="next"/>
</form>
</body>
</html>

I named this file as 2.php

<?php
session_start();
$name = $_POST['name'];
session_register('name');

?>
<html>
<body>
<form action="1.php" method="post">

<input type="submit"  value="back"/>
</form>
</body>

The problem is that I do not know how to implement this on the radio buttons . Could you please help me out Thanks in advance

  • 写回答

3条回答 默认 最新

  • duan39779 2012-06-04 05:25
    关注

    Try this one,

    1.php

    <?php
      session_start();
    ?>
    <html>
    <body>
    <form action="2.php" method="post">
    
    Radio1 <input type="radio" name="name" value="radio1" <?php if($_SESSION['name'] == 'radio1') echo "checked='checked'" ?>/><br/>
    Radio2 <input type="radio" name="name" value="radio2" <?php if($_SESSION['name'] == 'radio2') echo "checked='checked'" ?>/><br/>
    Radio3 <input type="radio" name="name" value="radio3" <?php if($_SESSION['name'] == 'radio3') echo "checked='checked'" ?>/><br/>
    
    <input type="submit"  value="next"/>
    </form>
    </body>
    </html>
    

    2.php

    <?php
    session_start();
    $name = $_POST['name'];
    $_SESSION['name'] = $name;
    
    ?>
    <html>
    <body>
    <form action="1.php" method="post">
    
    <input type="submit"  value="back"/>
    </form>
    </body>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题