如何使用PHP从HTML表单收集数据? [英] How to collect data using php from an HTML form?
本文介绍了如何使用PHP从HTML表单收集数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设有一个HTML文件,其中包含一些表单,其中包含一些数据,这些数据是用户使用textarea和复选框输入的。如何将这些数据发送到PHP文件?
解决方案
所有表单变量将在php中使用$ _GET或$ _POST数组(取决于您使用哪种方法提交表单。
textarea或复选框需要像这样命名:
<! - HTML form - >
< form method =postaction =collect.php>
评论:< textarea name =comments cols =20rows =5>< / textarea>< br />
勾选以选择< input type =复选框name =checker/>
< / form>
// collect.php
$ comments =; if(isset($ _ POST [comments])) {$ comments = $ _POST [comments];}
checker =; if(isset($ _ POST [checker])){$ comments = $ _POST [checker];}
Suppose there is a HTML file that has a form in it , which contains some data , which have been taken input from the user using textarea and checkbox . How do I send this data across to a PHP file ?
解决方案
All form variables will be in $_GET or $_POST array in php (depending on which method you use to submit the form.
The textarea or checkbox need to be named like this:
<!-- HTML form -->
<form method="post" action="collect.php">
Comments: <textarea name="comments" cols="20" rows="5"></textarea> <br/>
Tick to select <input type="checkbox" name="checker"/>
</form>
// collect.php
$comments=""; if(isset($_POST["comments"])) { $comments = $_POST["comments"]; }
$checker=""; if(isset($_POST["checker"])) { $comments = $_POST["checker"]; }
这篇关于如何使用PHP从HTML表单收集数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文