php显示提交的数据,php表单提交到数据库

PHP 如何把多次提交后数据记住并显示出来。

提交一次就在cookie里添加一次呗,可以用逗号分隔,然后显示的时候用explode()函数转化成数组再输出

我们提供的服务有:成都网站建设、网站建设、微信公众号开发、网站优化、网站认证、遂平ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的遂平网站制作公司

另外你的那种写法在没有设置过cookie的时候会报错

if(isset($_POST["submit"])){

if(isset($_COOKIE["xl"])){

$xl=$_COOKIE["xl"].",".$_POST['xl'];

setcookie("xl",$xl);

echo "pre";

print_r(explode(",",$_COOKIE["xl"]));

echo "/pre";

}else{

$xl=$_POST['xl'];

setcookie("xl",$xl);

}

}

希望能帮到你

PHP怎么样让内容提交后再显示出来提交的内容呢?

?php

header("Content-Type: text/html; charset=utf-8"); //页面默认utf-8

//数据库

$connec=mysql_connect('localhost','root','root') or die('no mysql server: '.mysql_error());

mysql_select_db('201504',$connec) or die ('no mysql: '.mysql_error());

mysql_query("set names 'utf8'");

$so=$_GET["so"]; //用这个做查询就是了index.php?so=12345

//=======添加

if(@$_GET["action"]=="add"){

$title=$_POST["title"];

$content=$_POST["content"];

$sql="insert into shujubiao001 (title,content) values ('$title','$content')"; 

mysql_query($sql);

header("Location: test.php"); 

}

?

本页面为test.php br

本页链接数据库,添加,查询 br

form action="?action=add" method="post"

标题:input type="text" name="title"

内容:input type="text" name="content"

input type="submit" 

/form

form action="" method="get"查询标题

input type="text" name="so"input type="submit" 

/form

? //查询输出

$sql="select * from shujubiao001 where (title like '%$so%') "; //只搜索标题

//$sql="select * from shujubiao001 where (title like '%$so%' or content like '%$so%') "; //搜索标题+内容

$result=@mysql_query($sql,$connec);

if (mysql_num_rows($result)){

while(@$row=mysql_fetch_array($result)){ ?

?echo $row[id];? - ?echo $row[title];? - ?echo $row[content];? br

? }}else{echo "p align='center'没有查到相关记录/p";}?

Html提交数据到php,如何打开php文件查看我提交的数据?

比如表单里有个input name = “username"

php里面可以写 

?php echo $_POST["username"]?

form的内容如果按 post方式提交,php会将数据放到_POST数组中。

如果你想查看 用echo 命令打印这个数组值就行了。

php代码用 ?php ?包起来

不过这需要先搭好服务器,配置好php环境

PHP怎么获取表单提交的数据啊?

一、用file_get_contents以get方式获取内容,需要输入内容为:

1、?php

2、$url='';

3、$html = file_get_contents($url);

4、echo $html;

5、?

二、用file_get_contents函数,以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 "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\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函数打开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\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、function GetUrlHTML($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、   return false;

35、}

36、?

参考资料:

php-file_get_contents

当前题目:php显示提交的数据,php表单提交到数据库
网页链接:https://www.cdcxhl.com/article2/dsieeoc.html

成都网站建设公司_创新互联,为您提供移动网站建设网站建设企业网站制作建站公司服务器托管ChatGPT

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

商城网站建设