简体   繁体   English

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

[英]Pass form data to another page with php

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 $email is the email address the user entered into the form. 其中$email是用户在表单中输入的电子邮件地址。 How exactly do I accomplish this? 我究竟该如何做到这一点?

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 的index.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 site2.php

 <html>
 <body>

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

 </body>
 </html> 

output 产量

Hello "name" ! 你好“名字”!

Your email is "whatyou@addedonindex.com" . 您的电子邮件是“whatyou@addedonindex.com”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM