php表單所有數(shù)據(jù) php表單顯示數(shù)據(jù)庫內(nèi)容

PHP怎么獲取表單提交的數(shù)據(jù)啊?

一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:

創(chuàng)新互聯(lián)建站專業(yè)提供達(dá)州服務(wù)器托管服務(wù),為用戶提供五星數(shù)據(jù)中心、電信、雙線接入解決方案,用戶可自行在線購買達(dá)州服務(wù)器托管服務(wù),并享受7*24小時(shí)金牌售后服務(wù)。

1、?php

2、$url='';

3、$html=file_get_contents($url);

4、echo$html;

5、?

二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為

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方式獲取內(nèi)容,需要輸入內(nèi)容為

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方式獲取內(nèi)容,需要輸入內(nèi)容為

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函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為

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怎么獲取表單中的多條數(shù)據(jù)

在生成的表單元素以及之前的元素的名字加上中括號(hào)即可實(shí)現(xiàn)

比如: name="contents" = name="contents[]",最后提交獲取到的數(shù)據(jù)是一個(gè)數(shù)組形式的。

代碼如下:

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);

}

?

得到的數(shù)據(jù)是數(shù)組形式的,遍歷即可。

php用表單形式顯示數(shù)據(jù)庫信息

初學(xué)者寫的,你可以試試

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(服務(wù)器,用戶名,密碼)

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

//?mysql_select_db(數(shù)據(jù)庫,$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表單所有數(shù)據(jù) php表單顯示數(shù)據(jù)庫內(nèi)容
網(wǎng)頁鏈接:http://bm7419.com/article8/ddcdhop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、網(wǎng)站制作動(dòng)態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化