你訪問的是文件路徑,并不是服務(wù)地址;

創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、成都網(wǎng)站設(shè)計與策劃設(shè)計,修文網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:修文等地區(qū)。修文做網(wǎng)站價格咨詢:18982081108
你訪問Localhost或127.0.0.1,具體要看你指向的目錄
我在我的本地測試了,可以得到
==============================
name.html
----------
html
head
titleadsf/title
/head
body
form action="hh.php" method="post"
Name: input type="text" name="name1" /
Age: input type="text" name="age" /
input type="submit" /
/form
/body
/html
===================================
hh.php
-----------
html
head
titleadsf/title
/head
body
Welcome ?php
echo $_POST["name1"];?.br /
You are ?php echo $_POST["age"];? years old.
/body
/html
**********************************************
輸入:
| 名字:asdfadff
| 年齡:13
--------------------------------------------
--------------------------------------------
結(jié)果:
Welcome asdfadff.
You are 13 years old.
******************************************************************
我覺的即使你那樣解決了,也不是問題的根本
因為我這里能夠測試成功,說明那個是沒有問題的
還有,你可以試試把HTML格式寫全
后臺獲取前端表單的值,依賴于表單控件的name屬性,而?INPUT id="token" VALUE ="證明材料" 并沒有設(shè)定name屬性,所以獲取不到,應(yīng)該改為?INPUT name="token" id="token" VALUE ="證明材料"
一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
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方式獲取內(nèi)容,需要輸入內(nèi)容為
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"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打開url,以post方式獲取內(nèi)容,需要輸入內(nèi)容為
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函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
1、?php
2、functionget_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、returnfalse;
10、}else{
11、$request="GET$queryHTTP/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、functionGetUrlHTML($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、?returnfalse;
35、}
36、?
參考資料:
php-file_get_contents
?
echo $_POST['textfield'];
?
因為服務(wù)器禁止了全局自動變量。獲取表單得用$_POST或者$_GET
我測試了下代碼
首先 PHP 沒有now()這個函數(shù)
第二 'null', '.$title.', '.$keywords.', '.$author.', '.$content.',$addtime)"; 這些變量前面后面的點都是做什么的?
把now()函數(shù)去掉可以正常插入數(shù)據(jù)庫 就是每條數(shù)據(jù)前后都帶“.”
修改后代碼
?php
$con = mysql_connect("localhost","root","1") or die( " xxxxx");
mysql_select_db("newsdb",$con);
$id = $_POST[id];
$title = $_POST[title];
$keywords = $_POST[keywords];
$author = $_POST[author];
$content = $_POST[content];
$sql = "INSERT INTO `newsdb`.`news` (`id`, `title`, `keywords`, `author`, `content`, `addtime`) VALUES ('null', '$title', '$keywords', '$author', '$content',now())";
if(mysql_query($sql,$con))
{
echo "ok,the data is ok!";
}
?
當前名稱:php獲取不到表單數(shù)據(jù) php獲取不到表單數(shù)據(jù)的原因
本文網(wǎng)址:http://www.chinadenli.net/article40/dooeseo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站營銷、關(guān)鍵詞優(yōu)化、、網(wǎng)頁設(shè)計公司、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)