導航:首頁 > 編程語言 > php可以將表單數據

php可以將表單數據

發布時間:2025-03-02 19:55:17

『壹』 php接收表單數據存儲數組,並按格式輸出

可以先接收到值。然後組裝成
123,456,789 這樣的字元串存入數脊知據庫
然後頃兄讀取資料庫的時候,用explode() 把他轉為櫻乎消數組,在循環輸出就可以了

$url1 = $_POST('url1');

$url2 = $_POST('url2');

$url3 = $_POST('url3');
組裝數據
$str = $url1.",".$url2.",";
然後將$str 存入資料庫
然後你讀取這條數據。讀出來是這樣的
$new_str = "123,456,789 ";
然後
$array = explode(',',$new_str);
var_mp($array);

『貳』 PHP怎麼獲取表單提交的數據啊

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

1、<?php

2、$url='http://www.domain.com/?para=123';

3、$html = file_get_contents($url);

4、echo $html;

5、?>

二、用file_get_contents函數,以post方式獲取url,需要輸入內容為

1、<?php

2、$url = 'http://www.domain.com/test.php?id=123';

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 " .

9、 "Content-Length: " . strlen($data) . " ",

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 "url header: {$header} <br>":

8、echo "url body: $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 Cookie:cook1=c3;cook2=c4 " .

8、"Content-Length: " . strlen($data) . " ",

9、'content' => $data

10、)

11、);

12、$context = stream_context_create($opts);

13、$html = fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb' ,false, $context);

14、$w=fread($html,1024);

15、echo $w;

16、?>

五、用fsockopen函數打開url,以get方式獲取完整的數據,包括header和body,需要輸入內容為

1、?php

2、function get_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、return false;

10、} else {

11、$request = "GET $query HTTP/1.1 ";

12、$request .= "Host: $url[host] ";

13、$request .= "Connection: Close ";

14、if($cookie) $request.="Cookie: $cookie ";

15、$request.=" ";

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、function GetUrlHTML($url,$cookie=false)

26、{

27、$rowdata = get_url($url,$cookie);

28、if($rowdata)

29、{

30、$body= stristr($rowdata," ");

31、$body=substr($body,4,strlen($body));

32、return $body;

33、}

34、 return false;

35、}

36、?>

『叄』 怎麼用php把html表單內容寫入資料庫

1:首先要使用PHP的超全局變數 $_GET 和 $_POST 用於收集表單數據(form-data)

2:然後使用INSERT INTO 語句用於向資料庫表中插入新記錄。

具體示例:

(1)首先創建了一個名為 "Persons" 的表,有三個列:"Firstname", "Lastname" 以及 "Age"。

<?php
$con=mysql_connect("localhost","peter","abc123");
if(!$con)
{
die('Couldnotconnect:'.mysql_error());
}

mysql_select_db("my_db",$con);

mysql_query("INSERTINTOPersons(FirstName,LastName,Age)
VALUES('Peter','Griffin','35')");

mysql_query("INSERTINTOPersons(FirstName,LastName,Age)
VALUES('Glenn','Quagmire','33')");

mysql_close($con);
?>

(2)其次創建一個 HTML 表單,這個表單可把新記錄插入 "Persons" 表。

<html>
<body>

<formaction="insert.php"method="post">
Firstname:<inputtype="text"name="firstname"/>
Lastname:<inputtype="text"name="lastname"/>
Age:<inputtype="text"name="age"/>
<inputtype="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('Couldnotconnect:'.mysql_error());
}

mysql_select_db("my_db",$con);

$sql="INSERTINTOPersons(FirstName,LastName,Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if(!mysql_query($sql,$con))
{
die('Error:'.mysql_error());
}
echo"1recordadded";

mysql_close($con)
?>
閱讀全文

與php可以將表單數據相關的資料

熱點內容
python中刪除csv 瀏覽:591
oracle創建表空間命令 瀏覽:14
十塊錢五分鍾的解壓人偶 瀏覽:934
學android看什麼書 瀏覽:376
網路加密了手機上怎樣顯示 瀏覽:805
文章被以什麼形式存放在伺服器中 瀏覽:708
炮兵命令 瀏覽:116
網商園app怎麼樣啊 瀏覽:325
app字體大小怎麼設置在哪 瀏覽:432
華為app選擇網路模式哪裡找 瀏覽:321
策劃優化伺服器是什麼 瀏覽:238
聯想的組織伺服器怎麼連接 瀏覽:218
程序員千里貴州頭條 瀏覽:672
阿里雲伺服器199一年 瀏覽:688
支點app裡面有幣怎麼辦 瀏覽:65
程序員ps 瀏覽:720
滴滴app順風車怎麼更換車輛信息 瀏覽:22
胡萊三國怎麼更換伺服器 瀏覽:816
木解壓神器中的鋼琴彈出兒童歌曲 瀏覽:530
買單吧app付款怎麼退款 瀏覽:648