如何在会话中存储单选按钮以在另一页上使用? [英] How to store a radio button in a session for use on another page?

查看:56
本文介绍了如何在会话中存储单选按钮以在另一页上使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我需要在会话中存储所选单选按钮的选项,然后根据该值在不同页面上执行操作。



Page1.php:

 < input type =radioname =personvalue =p1/> Person1 
< ; input type =radioname =personvalue =p2/> Person2

Page2.php

 如果在第一页选择了Person1 
//如果选择Person2则执行此
一页两页
//这样做


解决方案

您可以通过将表单中的数据发布到您不需要会话的Page2.php页面来完成此操作。

  $ _ POST [person]; 

会将数据提取出来,以便您可以执行:

  string person = $ _POST [person] 
if(person == something){
//做点什么
}
else {
//做别的事
}

只有你如果您打算使用多次返回的变量值,则需要一个会话。如果是这种情况,那么你可以在这里找到一个很好的简单教程:



http://www.w3schools.com/php/php_sessions.asp



在你的Page2中,基本的东西看起来就像这样.php:

  session_start(); 
$ _SESSION [person] = $ _POST [person];

希望有所帮助!


So I need to store the choice of selected radio button in session and then based on that value perform an action on a different page.

Page1.php:

 <input type="radio" name="person" value="p1"/>Person1
 <input type="radio" name="person" value="p2"/>Person2

Page2.php

if Person1 is selected on page one
  //do this
if Person2 is selected one page two
  //do this

解决方案

You can do this by posting the data in your form through to your Page2.php page you don't need a session.

$_POST["person"];

Will pull the data out so that you can do:

string person = $_POST["person"]
if(person == something){
   //do something
}
else{
  //do something else
}

You only need a session if you intend to use the variable value that is returned on multiple occasions. If that's the case then you can find a good easy tutorial here:

http://www.w3schools.com/php/php_sessions.asp

The basics would look something like this within your Page2.php:

session_start();    
$_SESSION["person"] = $_POST["person"];

Hope that helps!

这篇关于如何在会话中存储单选按钮以在另一页上使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆