导航:首页 > 编程语言 > 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可以将表单数据相关的资料

热点内容
程序员如何不被废 浏览:803
二进制流转pdf 浏览:915
php判断爬虫 浏览:569
960除24除4简便算法 浏览:786
关于解压英语翻译 浏览:565
python控制键盘右键 浏览:920
php没有libmysqldll 浏览:828
时政新闻app哪个好 浏览:906
手机已加密怎么办 浏览:201
安卓手机截屏怎么传到苹果 浏览:527
京管家app哪里下载 浏览:33
文件夹横向排列的竖向排列 浏览:453
51单片机驱动摄像头模块 浏览:689
政府文件加密没法转换 浏览:373
android判断栈顶 浏览:331
凭证软件源码 浏览:860
androidwebview滚动事件 浏览:11
如何将电脑上的图片压缩成文件包 浏览:899
程序员转金融IT 浏览:839
黑马程序员培训效果如何 浏览:915