PHP在多个页面上传递多个变量 [英] PHP passing multiple variables across multiple pages
问题描述
我的网站涉及用户通过几页表单提交数据。我可以将在一页上提交的数据直接传递到下一页,但是我该如何将它发送到页面之后呢?这是我正在做的一个非常简化的版本。
第1页
echo'< form action ='page2.php'method ='post'>
请输入您的姓名:< input type ='text'name = 'Name'/>
< input type ='submit'value ='Submit'/>< / form>;
?>
第2页:
<?php
$ name = $ _ POST [Name];
echoHello $ name!< br />
< form action ='page3.php'method ='post'>
请输入您的请求:< input type ='text'name ='Req'/>
< input type ='submit'value ='提交'/>< / form>;
?>
第3页:
<?php
echo谢谢您的请求,$ name!;
?>
最后一页应该显示用户的名字,但显然它不起作用,因为我没有没有将该变量传递给页面。由于复杂的原因,我无法在同一页面上提交所有数据,因此我需要将所有内容分开。那么我怎样才能得到这个变量和其他的结果?
使用会话:
$
session_start();
$ _SESSION ['name'] = $ _POST ['name'];
然后在第3页,您可以回显 $ _ SESSION ['name']
My website involves a user submitting data over several pages of forms. I can pass data submitted on one page straight to the next page, but how do I go about sending it to pages after that? Here's a very simplified version of what I'm doing.
Page 1:
<?php
echo "<form action='page2.php' method='post'>
Please enter your name: <input type='text' name='Name'/>
<input type='submit' value='Submit'/></form>";
?>
Page 2:
<?php
$name=$_POST["Name"];
echo "Hello $name!<br/>
<form action='page3.php' method='post'>
Please enter your request: <input type='text' name='Req'/>
<input type='submit' value='Submit'/></form>";
?>
Page 3:
<?php
echo "Thank you for your request, $name!";
?>
The final page is supposed to display the user's name, but obviously it won't work because I haven't passed that variable to the page. I can't have all data submitted on the same page for complicated reasons so I need to have everything split up. So how can I get this variable and others to carry over?
Use sessions:
session_start();
on every page
$_SESSION['name'] = $_POST['name'];
then on page3 you can echo $_SESSION['name']
这篇关于PHP在多个页面上传递多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!