PHP:如何使用if语句发布到多个页面
好吧,这是我的痛苦;我希望有人能给我指出正确的方向。我有一个表单,它是一个多页面的php向导,但是每个后续页面都依赖于选择框中选择的选项。我有它重定向到适当的页面时,点击提交的基础上选择,但信息没有被张贴到页面上。所以我的问题是,我怎样才能在这两个页面上发布信息,以便下一个加载的页面可以在上一个页面中输入信息。下面是我当前代码的一个示例PHP:如何使用if语句发布到多个页面,php,Php,好吧,这是我的痛苦;我希望有人能给我指出正确的方向。我有一个表单,它是一个多页面的php向导,但是每个后续页面都依赖于选择框中选择的选项。我有它重定向到适当的页面时,点击提交的基础上选择,但信息没有被张贴到页面上。所以我的问题是,我怎样才能在这两个页面上发布信息,以便下一个加载的页面可以在上一个页面中输入信息。下面是我当前代码的一个示例 <html> <head></head> <body> <?php //let's start th
<html>
<head></head>
<body>
<?php
//let's start the session
session_start();
//now, let's register our session variables
session_register('info from last page');
//finally, let's store our posted values in the session variables
$_SESSION['info from last page'] = $_POST['info from last page'];
echo $_SESSION["info from last page"];
//redirect to appropriate page based on selected option
function redirect($where){
header("Location: $where");
}
if ($_REQUEST['audio'] == 'option1'){
redirect('http://www.avwebcasting.com/ordering_system/webcast/step3ressless.php');
}elseif($_REQUEST['audio'] == 'option2'){
redirect('http://www.avwebcasting.com/ordering_system/webcast/step3oa.php');
}
?>
<form method="post" id="step2" name="step2" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>
<span>*Audio:</span>
<select name="audio" class="select">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
</select>
</label>
<INPUT TYPE="submit" name="submit"/>
</body>
</html>
您可以在选项值中获取要重新检测的php文件的名称,然后可以使用一行解决方案:
redirect('http://www.avwebcasting.com/ordering_system/webcast/' . stripslashes($_REQUEST['audio']) . '.php');
或者我不理解这个问题您可以在选项值中获取要重新检测的php文件名,然后您可以使用一行解决方案:
redirect('http://www.avwebcasting.com/ordering_system/webcast/' . stripslashes($_REQUEST['audio']) . '.php');
或者我不理解这个问题对于初学者来说,您的会话无法工作的原因是因为您在会话开始之前输出了数据
<html> <<<
<head></head> <<<
<body> <<<
<?php
//let's start the session
session_start(); //this fails
对于初学者,会话无法工作的原因是会话开始前输出数据
<html> <<<
<head></head> <<<
<body> <<<
<?php
//let's start the session
session_start(); //this fails
这个
<?
session_start();
?>
<html>
<head></head>
<body>
<?
$locationArray = array(
'option1' => '/ordering_system/webcast/step3ressless.php',
'option2' => '/ordering_system/webcast/step3oa.php'
);
if(isset($_REQUEST['audio'])){
if(array_key_exists($_REQUEST['audio'],$locationArray)){
$location = $locationArray[$_REQUEST['audio']];
header('Location: '.$location);
exit;
}
}
// No one submitted the audio variable.. fall through to the form
?>
<form method="post" id="step2" name="step2" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label>
<span>*Audio:</span>
<select name="audio" class="select">
<option value="option1" selected="selected">option1</option>
<option value="option2">option2</option>
</select>
</label>
<INPUT TYPE="submit" name="submit"/>
</body>
</html>
这个
好的,经过几个小时的研究,我回答了我自己的问题。事实证明,它可以完美地与一些javascript配合使用;因此,我发布了我自己问题的答案,以帮助任何可能来到这些十字路口的人
<script type="text/javascript">
function PostMultiple()
{
if(document.step2.audio[0].selected == true) {
document.step2.action = 'http://gohere.html';
}
if(document.step2.audio[1].selected == true) {
document.step2.action = 'http://gothere.html';
document.myform.method = 'get';
}
return true;
}
</script>
函数PostMultiple()
{
if(document.step2.audio[0]。selected==true){
document.step2.actionhttp://gohere.html';
}
if(document.step2.audio[1]。selected==true){
document.step2.actionhttp://gothere.html';
document.myform.method='get';
}
返回true;
}
好的,经过几个小时的研究,我回答了自己的问题。事实证明,它可以完美地与一些javascript配合使用;因此,我发布了我自己问题的答案,以帮助任何可能来到这些十字路口的人
<script type="text/javascript">
function PostMultiple()
{
if(document.step2.audio[0].selected == true) {
document.step2.action = 'http://gohere.html';
}
if(document.step2.audio[1].selected == true) {
document.step2.action = 'http://gothere.html';
document.myform.method = 'get';
}
return true;
}
</script>
函数PostMultiple()
{
if(document.step2.audio[0]。selected==true){
document.step2.actionhttp://gohere.html';
}
if(document.step2.audio[1]。selected==true){
document.step2.actionhttp://gothere.html';
document.myform.method='get';
}
返回true;
}
如果(数组键存在($\u请求['audio']))
。。。请修改。尝试了奥利的例子,但信息仍然没有被传递。感谢所有人的回复if(数组密钥存在($\u请求['audio'])
。。。请修改。尝试了奥利的例子,但信息仍然没有被传递。感谢所有人的响应请在开发模式下打开错误报告,在会话开始()之前添加错误报告(E\u all)
要想知道PHP是怎么回事,只是一个无关的批评,试着把它当作建设性的批评让我们开始会话
是一个错误的评论。它比它所记录的代码要长,这已经足够清楚了-没有人需要注释来知道session\u start
启动会话。您应该记录代码背后的逻辑,而不是代码本身。与会话寄存器相同。你的评论应该指出你为什么要注册变量,而不是你在注册变量;任何人都能看到你在做什么,但你不能马上说出你为什么要这样做。只是一个无关的批评,试着把它当作建设性的批评让我们开始会话
是一个错误的评论。它比它所记录的代码要长,这已经足够清楚了-没有人需要注释来知道session\u start
启动会话。您应该记录代码背后的逻辑,而不是代码本身。与会话寄存器相同。你的评论应该指出你为什么要注册变量,而不是你在注册变量;任何人都能看到你在做什么,但你不能马上说出你为什么要这么做。