提交表单后,传递的数据值将保留在页面上

时间:2018-08-03 22:42:59

标签: php html mysql

我有2页,我想保留从page1.php传递的数据值

page1.php
  <form action='page2.php' method='POST' class='form-inline'>
  <input type='submit' class='btn btn-info' value='Manage Child' 
  name='manage'>;
  <input type='hidden' value='<?php echo $id;?>' name='id'>
  </form>

page2.php
$id = $_POST['id'];
if(isset($_POST['passinfo'])){
$studentid=$_POST['studid'];
}else{
$studentid='';
}
<form>
<input type='hidden' name='parentid' value='<?php echo $id;?>'
<input type='hidden' name='studentid' value='<?php echo $studentid;?>'
<input type='text' name='studentname'>
</form>
<form action='' method='POST'>
<input type='hidden' name=studid value='<?php echo $stud_id?'>
<input type='submit' class='btn btn-primary' value='Assign' name='passinfo'>
</form>

我的问题是,如果我单击“ passinfo”按钮并提交“ studid”值,则“ $ parentid”值将是不确定的变量。我的问题是,即使我提交表单,如何保持“ $ parentid”的值

1 个答案:

答案 0 :(得分:0)

您必须以一种形式放置隐藏的输入:

<form action='' method='POST'>
<input type="hidden" name="parentid" value='<?=$id?>'>
<input type="hidden" name="studentid" value='<?=$studentid?>'>
<input type='hidden' name=studid value='<?=$stud_id?'>
<input type='submit' class='btn btn-primary' value='Assign' name='passinfo'>
</form>