php表单所有数据 php表单显示数据库内容

PHP怎么获取表单提交的数据啊?

一、用file_get_contents以get方式获取内容,需要输入内容为:

创新互联建站专业提供达州服务器托管服务,为用户提供五星数据中心、电信、双线接入解决方案,用户可自行在线购买达州服务器托管服务,并享受7*24小时金牌售后服务。

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

PHP怎么获取表单中的多条数据

在生成的表单元素以及之前的元素的名字加上中括号即可实现

比如: name="contents" = name="contents[]",最后提交获取到的数据是一个数组形式的。

代码如下:

form name="form1" method="post" action="index.php?action=ok"

1.input type="text" name="contents[]" value=""

2.input type="text" name="contents[]" value=""

3.input type="text" name="contents[]" value=""

input type="submit" value="提交"

/form

?php

if($_GET['action'] == 'ok'){

$contents = $_POST['contents'];

print_r($contents);

}

?

得到的数据是数组形式的,遍历即可。

php用表单形式显示数据库信息

初学者写的,你可以试试

form name="myform" method="post" action="mysql.php"

table border="1"

tr

td width="605" height="51" bgcolor="#CC99FF" colspan="2"

div align="center"请输入用户名称

input name="txt_user" type="text" id="txt_user" size="25"nbsp;

input type="submit" name="Submit" value="查询"

/div

/td

/tr

tr

td align='center'用户名称/td

td align='center'年龄/td

/tr

?php

// mysql_connect(服务器,用户名,密码)

$link = mysql_connect("localhost","root","root");

// mysql_select_db(数据库,$link)

$db_selected = mysql_select_db("php_test",$link);

// 编码格式(貌似很重要)

mysql_query("set names 'utf8'");

?

?php

$sql = mysql_query("select name_,age_ from t_user");

$info = mysql_fetch_array($sql);

if($_POST[Submit]=="查询"){

$txt_user = $_POST[txt_user];

$sql = mysql_query("select * from t_user where name_ like '%".trim($txt_user)."%'");

$info = mysql_fetch_array($sql);

}

?

?php

if($info==false){

echo 'trtd width="605" height="51" bgcolor="#CC99FF" colspan="2"';

echo "div align='center' style='color:#FF0000;font-size:12px;'对不起,您查找的用户信息不存在!/div";

echo '/td/tr';

}elseif($info){

echo 'elseif';

}

?

?php

do{

?

tr align="center" bgcolor="#FFFFFF"

td height="20"align="center" ?php echo $info['NAME_']?/td

td ?php echo $info['AGE_']?/td

/tr

?php

}while($info = mysql_fetch_array($sql));

mysql_free_result($sql);

mysql_close($link);

?

/table

/form


新闻名称:php表单所有数据 php表单显示数据库内容
网页URL:http://lszwz.com/article/ddcdhop.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款