php表單提交數(shù)據 php提交post數(shù)據

PHP表單提交不同數(shù)據到數(shù)據庫的不同表的不同字段怎么實現(xiàn)?

你可以用 PHP 的 MySQLi 或 PDO 庫來實現(xiàn)。

創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,先為昭陽等服務建站,昭陽等地企業(yè),進行企業(yè)商務咨詢服務。為昭陽企業(yè)網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

首先,你需要使用這些庫中的函數(shù)連接數(shù)據庫,然后把表單中的字段值插入到相應的數(shù)據表中。

例如,如果你使用 MySQLi,你可以這樣寫:

$conn = mysqli_connect("hostname", "username", "password", "database_name");

$rwid = $_POST['rwid'];

$rwdj = $_POST['rwdj'];

$rwzb = $_POST['rwzb'];

$sql1 = "INSERT INTO table_a (s) VALUES ('$rwid')";

mysqli_query($conn, $sql1);

$sql2 = "INSERT INTO table_b (d) VALUES ('$rwdj')";

mysqli_query($conn, $sql2);

$sql3 = "INSERT INTO table_c (f) VALUES ('$rwzb')";

mysqli_query($conn, $sql3);

如果你使用 PDO,你可以這樣寫:

$conn = new PDO("mysql:host=hostname;dbname=database_name", "username", "password");

$rwid = $_POST['rwid'];

$rwdj = $_POST['rwdj'];

$rwzb = $_POST['rwzb'];

$stmt1 = $conn-prepare("INSERT INTO table_a (s) VALUES (:s)");

$stmt1-bindParam(':s', $rwid);

$stmt1-execute();

$stmt2 = $conn-prepare("INSERT INTO table_b (d) VALUES (:d)");

$stmt2-bindParam(':d', $rwdj);

$stmt2-execute();

$stmt3 = $conn-prepare("INSERT INTO table_c (f) VALUES (:f)");

$stmt3-bindParam(':f', $rwzb);

$stmt3-execute();

希望這個答案對你有幫助。

php表單提交內容到數(shù)據庫

我來給你代碼:

?php

$hostName?=?'yourhost';

$userName?=?'yourusername';

$passWords?=?'yourpwd';

$conn?=?mysql_conn($hostName,$userName,$passWords);

if(!$conn){

die('Could?not?connect:?'?.?mysql_error());

}

$mysql_select_db('admin',$conn);

$sql="INSERT?INTO?user_zy?(username,?name,?time,place,type,http,password)

VALUES

('$_POST[username]','$_POST[name]','$_POST[time]','$_POST[place]','$_POST[type]',

'$_POST[http]','$_POST[password]')";

mysql_query($sql,$conn);???//這里是添加數(shù)據。

//讀取數(shù)據

$sql?=?"select?*?form?user_zy?where?1";???//讀取所有。

$sql?=?"select?*?form?user_zy?where?id=".$id;???//讀取某一項。

$result?=?mysql_query($sql,$conn);

while($info?=?mysql_fetch_array($result)){

$arr[]?=?$info;?//$arr?為最后所要讀取的值。

}

可以用var_dump($arr)打印出來看看。

有什么不明白可以留言。

php 表單提交

"insert into student set 學號='$no',姓名='$n',年齡='$a',性別='$s',學院='$d'"

這個SQL語句可能有誤。

你確定你的 student 表 字段是 學號 姓名 這樣的中文嗎?

另外我用的是這樣的

"insert into 表名 (字段1,字段2) values(值1,值2)" 字段一般都是英文,用中文容易出錯。

你可以看一下你的表的結構。

PHP怎么獲取表單提交的數(shù)據?。?/h2>

一、用file_get_contents以get方式獲取內容,需要輸入內容為:

1、?php

2、$url='';

3、$html=file_get_contents($url);

4、echo$html;

5、?

二、用file_get_contents函數(shù),以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函數(shù)打開url,以get方式獲取完整的數(shù)據,包括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表單提交數(shù)據 php提交post數(shù)據
網頁URL:http://muchs.cn/article22/doshsjc.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網站App設計、電子商務、網站策劃定制網站、網站收錄

廣告

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

成都定制網站建設