2011-02-28 52 views
2

我正在PHP 5.3.5的页面上工作,而且似乎$_POST不包含从我的表单提交的数据。

这是HTML文件:

<html> 
<body> 

<form action="welcome.php" method="post"> 
Name: <input type="text" name="fname" /> 
Age: <input type="text" name="age" /> 
<input type="submit" /> 
</form> 

</body> 
</html> 

这是PHP文件:

<html> 
<body> 

Welcome <?php echo $_POST["fname"]; ?>!<br /> 
You are <?php echo $_POST["age"]; ?> years old. 

</body> 
</html> 

的问题是,表单值不过去了,所以我得到的输出是这样的:

 
Welcome ! 
You are years old. 

取而代之的是:

 
Welcome John! 
You are 28 years old. 

我在做什么错?

+0

您确定您已经发布过吗?你能看到邮件正文与标题中的信息? – alex 2011-02-28 02:13:28

+0

如果您在welcome.php上查看源代码,您是否看到php或只是空白? – 2011-02-28 02:16:34

+0

它返回空白页面 – naji 2011-02-28 02:42:23

回答

5

尝试<?php var_dump($_POST); ?>看看里面有什么。没有办法破坏$ _POST - 这将是别的东西。可能的服务器设置可能会禁用$ _POST。

0

是您的HTML表方法 se转至至POST

<form method="post" action="process.php"> 
<fieldset><legend>your data</legend> 
<input type="text" name="txtname" id="id_name" /> 
<input type="text" name="txtage" id="id_age" /> 
</fieldset> 
<button type="submit">OK</button> 
</form> 
+0

糟糕!我在回答时编辑过。 :) – tenshimsm 2011-02-28 02:31:24

0

您还没有发布,或什么是clobbering $_POST

如果您在尝试访问代码之前未在代码中提到$_POST,那么您尚未将其发布到脚本中。

0

这里工作,但在PHP 5.3.1。试试这个:

<!doctype html> 
<html> 
<head> 
<title>form</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body> 

<form method="post" action="process.php"> 
<fieldset><legend>your data</legend> 
<input type="text" name="txtname" id="id_name" /> 
<input type="text" name="txtage" id="id_age" /> 
</fieldset> 
<button type="submit">OK</button> 
</form> 

</body> 
</html> 


<?php 
if(isset($_POST["txtname"])) 
    $txtname = $_POST["txtname"]; 
else 
    unset($txtname); 
if(isset($_POST["txtage"])) 
    $txtage = $_POST["txtage"]; 
else 
    unset($txtname); 
?> 
<!doctype html> 
<html> 
<head> 
<title>form</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body> 

<p>Welcome <?=$txtname; ?>!<br /> 
You are <?=$txtage; ?> years old.</p> 
</body> 
</html> 
+0

抱歉,太多mistyping.Edited很多次。 :( – tenshimsm 2011-02-28 02:51:09

0

尝试在POST使用大写:

<form action="file.php" method="POST"> 

相反的:PHP 5.3

<form action="file.php" method="post"> 
2

从使用全局,预先设定的变量移开,像$ _POST,以避免漏洞。

这个问题,据我所知,从来没有使用过$ _POST或$ _GET的程序员可能会把它当作任何其他变量,并且自己面对安全威胁。

我还没有发现检索$ _POST数据的“正确”方法,但是我使用的方法看起来相当卫生。

<?php parse_url(file_get_contents("php://input"), $_POST)); ?> 

这传递解析HTTP POST字符串到$ _ POST变量

2

你检查你的php.ini?
一旦我设置post_max_sizeupload_max_filesize相同,我就会破坏我的帖子方法。我觉得post_max_size必须小于upload_max_filesize
用RHEL 6.0中的PHP 5.3.3测试

0

我也有同样的问题。我使用Windows记事本编辑.php文件,并意外地保存在Unicode编码的文件,这是创建问题。然后我把它保存在UTF-8编码中,它的功能就像一个魅力。希望这可能有所帮助。