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

热点内容
这是命令吗txt电子书下载 浏览:940
adb命令导出媒体库 浏览:826
华为云服务器多少钱 浏览:366
连看世界app怎么用 浏览:35
ipad解压专家怎么解压qq邮箱文件 浏览:252
php712安装 浏览:448
python远程桌面控制 浏览:215
操作系统scan算法 浏览:11
服务器板块有什么龙头 浏览:74
我的世界服务器成员怎么开创造 浏览:660
程序员郑州买房哪个区好 浏览:204
程序员发怒 浏览:823
安卓机看视频怎么没有小窗口 浏览:456
minecraft服务器怎么布置 浏览:306
怎么把安卓的东西转到已激活苹果 浏览:852
停止服务doss命令 浏览:878
u盘占内存但该文件夹为空 浏览:612
服务器怎么更换重生点 浏览:34
收费api调用平台源码 浏览:648
安卓怎么自检病毒 浏览:560