我需要保存我的提交表单数据,比如:两页的名称。。。由于某些原因,$_POST只保存"操作"页面的数据,但在操作页面之后无法重试。这是我的代码:HTML(表单):
<html>
<body> <form name="input" action="staff.php" method="post">
Username: <input type="text" name="Name">
<input type="submit" value="Submit">
</form>
</body>
</html>
这是提交后的下一页,它有效。。。(staff.php)
<html>
<?php
session_start();
echo "You have choosen". $_POST['Name']; // it shows what you've choosen...
?>
<form name="input" action="staff2.php" method="post">
Age: <input type="text" name="Age">
<input type="submit" value="Submit">
</form>
</html>
好的,在年龄提交姓名和年龄后停止工作。。。(staff2.php)这是代码:
<?php
session_start();
echo "You have choosen".
$_POST['Name']; //it does't show Name.. Please help!
$_POST['Age']; // it doesnt't show this either..
?>
显然,第一页没有任何错误。所以不要改变任何事情。
第二页。这个帖子很管用。然后添加一个隐藏的输入以保存它,并将其携带到下一个:
<?php
echo "You have chosen: ". $_POST['Name']; // it shows what you've choosen...
?>
<form name="input" action="staff2.php" method="post">
Age: <input type="text" name="Age">
<input type="hidden" name="Name" value="<?php echo $_POST['Name']; ?>" /> <!-- this one -->
<input type="submit" value="Submit">
</form>
在第三页也是最后一页。正确连接变量:
echo 'You have chosen: <br/>';
echo $_POST['Name'] . '<br/>'; // this should carry the hidden input you set on the last page
echo $_POST['Age'];
//^^ you forgot the echo
当您有一个会话正在运行时,将它们作为会话变量传递。
$_SESSION['name'] = $_POST['name'];