Php 在页面之间保留表单值
我有两个PHP页面,其中一个是我输入的年份,提交年份值后,通过表单输入进入下一页,如图所示,在这里输入图像描述 第一页的代码是Php 在页面之间保留表单值,php,html,Php,Html,我有两个PHP页面,其中一个是我输入的年份,提交年份值后,通过表单输入进入下一页,如图所示,在这里输入图像描述 第一页的代码是 <div class="col-sm-12" style="background-color:lavender;"> <form method="post" action="next.php"> <table id="emi" width="100%"> <tr>
<div class="col-sm-12" style="background-color:lavender;">
<form method="post" action="next.php">
<table id="emi" width="100%">
<tr>
<td width="100%">
<div align="center"><b>
<h3> Enter Fiancial Information:</h3>
</b> </td>
<table width="100%" border="0" id="emi">
<tr>
<td><strong>First Calender Year of DATA! ( i.e. 1999 ) </strong></td>
<td><input type="text" class="form-control" placeholder="Enter the First Assesment Year" name="year" pattern="\d*" maxlength="4"></td>
<td><input type="submit" value="Go" name="submit"class="btn btn-success"></td>
</tr></table>
</table></form>
</table>
输入财务信息:
数据的第一个日历年!(即1999年)
我有两个PHP页面,其中一个是我输入的年份,提交年份值后,通过表单输入进入下一页,如图所示,在这里输入图像描述
在下一页中,我还有一个表单输入,在下一页中输入值后,单击“计算”按钮,我们从第一页调用的年份值消失。如图所示
在创建第一个页面后调用next.php的代码
<?php
error_reporting(0);
$year=$_REQUEST['year'];
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>
损益表
31-03-
31-03-
31-03-
当您通过“计算”按钮在第二页提交表单时,$\u请求['year']
不再设置,因为它来自上一个请求
一种解决方法是添加一个隐藏的输入字段,用于存储下一个请求的$\u请求['year']
值。
像这样的方法应该会奏效:
<input type="hidden" name="year" value="<? echo $_REQUEST['year']; ?>">
用此代码替换next.php
<?php
error_reporting(0);
$year=$_REQUEST['year'];
if($year==null){
$year=$_POST['year'];
}
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="hidden" id="year" name="year" value="<?php echo($year);?>">
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>
损益表
31-03-
31-03-
31-03-
提交表单时,只有标记中的值才能被发送。您需要将年份值添加为(隐藏)输入字段,以便在提交后保留它们。不要像在第二个代码中那样将
放在
之后。在表单中创建表,就像在第一个代码中一样