php 使用php将表单数据传递到另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15236733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:52:03  来源:igfitidea点击:

Pass form data to another page with php

phpforms

提问by user1543782

I have a form on my homepage and when it is submitted, it takes users to another page on my site. I want to pass the form data entered to the next page, with something like:

我的主页上有一个表单,当它被提交时,它会将用户带到我网站上的另一个页面。我想将输入的表单数据传递到下一页,例如:

<?php echo $email; ?>

Where $emailis the email address the user entered into the form. How exactly do I accomplish this?

$email用户在表单中输入的电子邮件地址在哪里。我究竟如何做到这一点?

回答by Stepo

The best way to accomplish that is to use POST which is a method of Hypertext Transfer Protocol https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

实现这一目标的最佳方法是使用 POST,这是一种超文本传输​​协议https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

index.php

索引.php

<html>
<body>

<form action="site2.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">
</form>

</body>
</html> 

site2.php

网站2.php

 <html>
 <body>

 Hello <?php echo $_POST["name"]; ?>!<br>
 Your mail is <?php echo $_POST["mail"]; ?>.

 </body>
 </html> 

output

输出

Hello "name" !

你好“名字”!

Your email is "[email protected]" .

您的电子邮件是“whatyou@ addedonindex.com”。