我正在使用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 :(得分:5)
试试<?php var_dump($_POST); ?>
,了解其中的真实情况。 $ _POST没有办法被打破 - 这将是别的东西。可能是服务器设置可能会禁用$ _POST。
答案 1 :(得分:2)
这可能是因为你打开了magic_quotes_gpc。你应该把它关掉: http://www.php.net/manual/en/security.magicquotes.disabling.php
答案 2 :(得分:2)
PHP 5.3正在逐渐使用全局预设变量(如$ _POST)来避免漏洞。
正如我所理解的那样,问题在于,从未使用$ _POST或$ _GET的程序员可能会将其视为任何其他变量,并将自己置于安全威胁之中。
我还没有发现检索$ _POST数据的“正确”方法,但我使用的方法看起来相当卫生。
<?php parse_url(file_get_contents("php://input"), $_POST);
这会将解析后的HTTP POST字符串传输到$ _POST变量
答案 3 :(得分:2)
你检查一下你的php.ini吗?
一旦我将post_max_size
与upload_max_filesize
设置为相同,我就破坏了我的帖子方法。
我认为post_max_size
必须小于upload_max_filesize
在RHEL 6.0中使用PHP 5.3.3进行测试
答案 4 :(得分:0)
您的HTML表单方法是否设置为 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>
答案 5 :(得分:0)
你还没有张贴过,或者有些东西正在破坏$_POST
。
如果您在尝试访问代码之前未在代码中提及$_POST
,那么您还没有发布到您的脚本。
答案 6 :(得分: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>
答案 7 :(得分:0)
请查看这篇文章http://getluky.net/2009/02/24/php-_post-array-empty-although-phpinput-and-raw-post-data-is-available。它对我有用:)
答案 8 :(得分:0)
尝试在POST中使用大写字母:
<form action="file.php" method="POST">
而不是:
<form action="file.php" method="post">
答案 9 :(得分:0)
我也有同样的问题。我使用Windows记事本编辑.php文件,并意外地以Unicode编码保存文件,这就产生了问题。然后我用UTF-8编码保存了它,它就像一个魅力。希望这可能有所帮助。