资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php表单本页提交数据,php表单提交有哪几种方式

php form表单怎么把数据提交到本页而不跳转?

PHP把表单提交到本页,这个的话,我们是通过form action="提交的文件名"来实现的,还有一个传值的方式,post或者是get可以通过METHOD来实现的,这里我写一段代码:

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

html

head/head

body

form action='文件名' method="post"

姓名input type='text' value=""

密码input type='text' value=""

emailinput type='text' value=""

/form

/body

/html

php表单怎样提交到当前页面,并用$_POST获取其值?

?php

/** filename : index.php */

header('content-type:text/html;charset=utf-8');

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

print_r($_POST);  // 打印 POST 中的所有数据

die;

}

?

form action method='post'  // 不要写action的值或写当前文件名(index.php) 就会提交到当前页面

...

input type='submit' name='submit' /

/form

如何用php页面提交表单到数据库

1:首先要使用PHP的超全局变量 $_GET 和 $_POST 用于收集表单数据(form-data) 2:然后使用INSERT INTO 语句用于向数据库表中插入新记录。 具体示例: (1)首先创建了一个名为 "Persons" 的表,有三个列:"Firstname", "Lastname" 以及 "Age"。

php表单提交到本页是什么意思?

就是form表单的action值为空或者写本页面的地址,那么表单里面的内容数据就会默认提交到这个action值的页面。

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表单提交有哪几种方式
标题路径:http://cdkjz.cn/article/hddggg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220