
正文
php表单输入数据 表单与php输入输出
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP,表单问题。 比如,我们要循环输入,表单数据。
//使用数组的方法存入,示例如
//index.php
!DOCTYPE html
html
head
meta http-equiv="X-UA-Compatible" content="IE=Edge" /
meta http-equiv="content-type" content="text/html;charset=utf-8" /
titlephp/title
body
form method="POST" action="01.php"
?php
for($i=0;$i10;$i++)
{
echo "第".$i."个人姓名:";
?
input type ="text" name="name[]" br/
?php
}
?
input type ="submit" name="btn" value='提交' br/
/form
/body
/html
//01.php
?php
if($_POST){
$name=$_POST['name'];
print_r($name);
}
/**
Array
(
[0] = chinawinxp1
[1] = chinawinxp2
[2] = chinawinxp3
[3] = chinawinxp4
[4] = chinawinxp5
[5] = chinawinxp6
[6] = chinawinxp7
[7] = chinawinxp8
[8] = chinawinxp9
[9] = chinawinxp10
)**/
?
相关问答
Q1: 在php怎么实现通过表单获取一些信息的输入这种功能?
临时纯手打一份
form method="post" action=""
input type="text" name="name" /
/form
?php
$name=$_POST['name'];//通过post方式获取 form表单中的 name值
echo $name; //输出获取到的name值。
?
使用方法php表单输入数据,新建一个 .php的文件php表单输入数据,将该代码拷贝进去php表单输入数据,然后放出php环境php表单输入数据,访问该文件即可。
纯手打php表单输入数据,望采纳,可追问。
Q2: php插入数据到数据库表单
表单应该使用名字,例如:
form action=xxx.php method=post
select name="select1"
option value="1" selected="selected"男/option
option value="0"女/option
/select
/form
这样,在xxx.php里面使用$_POST['select1']获取结果。
Q3: PHP怎么获取表单提交的数据啊?
一、用file_get_contents以get方式获取内容,需要输入内容为:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函数,以post方式获取url,需要输入内容为
1、?php
2、$url='';
3、$data=array('foo'='bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=array(
7、 'method'='POST',
8、 'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、 "Content-Length:".strlen($data)."\r\n",
10、 'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打开url,以get方式获取内容,需要输入内容为
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//获取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打开url,以post方式获取内容,需要输入内容为
1、?php
2、$data=array('foo2'='bar2','foo3'='bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie: $cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//获取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、 returnfalse;
35、}
36、?
参考资料:
php-file_get_contents
Q4: php新手在线等答案:用php如何让提取html表单中输入的数据???
在form中,的属性method=get
或者post方法,
在php中获取表单数据如下:
$_get[表单名]
$_post[表单名]
这样就可以获取到html中表单里面的数据信息
Q5: 怎么用php把html表单内容写入数据库
1:首先要使用PHPphp表单输入数据的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data)
2:然后使用INSERT INTO 语句用于向数据库表中插入新记录。
具体示例:
(1)首先创建php表单输入数据了一个名为 "Persons" 的表php表单输入数据,有三个列:"Firstname", "Lastname" 以及 "Age"。
?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");
mysql_close($con);
?
(2)其次创建一个 HTML 表单,这个表单可把新记录插入 "Persons" 表。
html
body
form action="insert.php" method="post"
Firstname: input type="text" name="firstname" /
Lastname: input type="text" name="lastname" /
Age: input type="text" name="age" /
input type="submit" /
/form
/body
/html
(3)接着当用户点击上例中 HTML 表单中的提交按钮时,表单数据被发送到 "insert.php"。"insert.php" 文件连接数据库,并通过
$_POST 变量从表单取回值。然后,mysql_query() 函数执行 INSERT INTO 语句,一条新的记录会添加到数据库表中。
?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?
关于php表单输入数据和表单与php输入输出的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







