首页 新闻 会员 周边

php中post接收不到数据

0
悬赏园豆:20 [待解决问题]

html文件代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body style="background-color: bisque">
<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">
<div style="text-align: center;margin-top: 10%">
<span>username:</span>
<input type="text" name="name" id="name" value=""/>
<br/>
<span>password:</span>
<input type="password" name="password" id="password" value=""/>
<br/>
<input type="submit" value="登录" style="width: 100px">
</div>
</form>
</body>
</html>

index.php代码如下:

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016-04-20
* Time: 15:24
*/

var_dump($_POST);
die();




打印输出的结果为:
array (size=0)
  empty


请问错在哪里呢,get可以接收到,post不行。是哪里没有配置好吗
negidan的主页 negidan | 初学一级 | 园豆:136
提问于:2016-04-26 14:35
< >
分享
所有回答(3)
0
  1. I can't read my POST HTTP request's body with PHP !
  2. Can't get $_POST values (php, html)

你可以嘗試打印

var_dump($_SERVER); //輸出請求

var_dump($_REQUEST); //輸出所有請求的數據

注:我複製你的代碼,運行之後,index.php可以正常獲取到$_POST的數據,不清楚是否是環境的問題。

五毛钱的饼 | 园豆:517 (小虾三级) | 2016-04-27 09:30

那应该就是环境的问题了

支持(0) 反对(0) negidan | 园豆:136 (初学一级) | 2016-04-27 16:44
0

enctype="application/x-www-form-urlencoded"。。。

你写错了吧。。。enctype,是用来设置,上传文件使用的。你要设置content-type。

 

汗,写错了。。。可以设置这个值,但是你试试不设置呢。

Supper_litt | 园豆:827 (小虾三级) | 2016-04-27 16:00

不设置也是不行的。。。

支持(0) 反对(0) negidan | 园豆:136 (初学一级) | 2016-04-27 16:45
0

用排除法,把代码精简,加上类似firebug的工具辅助调试

慧☆星 | 园豆:5640 (大侠五级) | 2016-04-28 17:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册