用PHP将表单数据传递给另一个页面 [英] Pass form data to another page with php

查看:116
本文介绍了用PHP将表单数据传递给另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 <?php echo $ email; ?> 

其中 $ email 是电子邮件地址用户输入表单。如何完成这项工作?

解决方案

完成此操作的最佳方法是使用POST,这是一种超文本传输​​协议 https://developer.mozilla.org/en-US/docs/ Web / HTTP / Methods



index.php $ b

 < HTML> 
< body>

< form action =site2.phpmethod =post>
名称:< input type =textname =name>
电子邮件地址:< input type =textname =email>
< input type =submit>
< / form>

< / body>
< / html>

site2.php

 < html> 
< body>

你好<?php echo $ _POST [name]; ?>!<峰; br>
您的邮件是<?php echo $ _POST [mail]; ?取代。

< / body>
< / html>

输出

您好名字!



您的电子邮件地址是whatyou@addedonindex.com。


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. 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

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

 <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" .

这篇关于用PHP将表单数据传递给另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆