我在“index.php”页面中创建了一个文本字段和一个下拉列表以及一个按钮,如下所示:
<form value="indexform" action="" method="post">
<b>Number:</b><input type="text" name="number"/><br/>
<b>Network:</b>
<select name="network">
<option selected="">please...</option>
<option value="1">Bsnl</option>
<option value="2">Idea</option>
</select>
<input type="submit" name="proceed" value="submit">
</form>
我已经使用了以下形式的PHP代码:
<?php
if(isset($_POST['network']) && isset($_POST['number']))
{
$number = $_POST['number'];
$network = $_POST['network'];
}
if(!empty($_POST['network']))
{
switch($network)
{
case "1":header("Location:Bsnl.php");break;
case "2":header("Location:Idea.php");break;
default:exit();
}
?>
我已经创建了两个页面“Bsnl.php”和“Idea.php”根据下拉列表中的选择,页面将被重定向到Bsnl / Idea.php
我创建了包含一个文本字段和提交按钮的Bsnl / Idea.php页面,代码如下:
<form value="Bsnlform action="default.php" method="post">
<b>Amount:</b><input type="text" name="amount"/><br>
<input type="submit" value="submit">
</form>
php代码如下:
<?php
if(!empty($_POST['amount']))
{
$amount = $_POST['amount'];
}
?>
atlast我想打印default.php页面上的整个表单细节(索引形式以及Bsnl / idea表单)任何人都可以帮我如何在default.php上打印值到现在为止我试过了php代码如下:
<?php
echo $amount;
echo $network;
echo $number;
?>
答案 0 :(得分:0)
首先,您需要启用session_start(); 并改为这样....
<?php
//Enable session first
session_start();
//Flush any existing session variables, you can choose where/if you wanna do this
session_unset();
if(isset($_POST['network']) && isset($_POST['number']))
{
$_SESSION['number'] = $_POST['number'];
$_SESSION['network'] = $_POST['network'];
}
if(!empty($_POST['network']))
{
switch($_SESSION['network'])
{
case "1":header("Location:Bsnl.php");break;
case "2":header("Location:Idea.php");break;
default:exit();
}
?>
然后将此更改为....
<?php
//Session enable again
session_start();
if(!empty($_POST['amount']))
{
$_SESSION['amount'] = $_POST['amount'];
}
?>
然后在你的下一个文件....
<?php
session_start();
echo $_SESSION['amount'];
echo $_SESSION['network'];
echo $_SESSION['number'];
?>
当然在你的另一页上,你不会回应$ _SESSION ['amount'],因为它还没有设置......