PHP - 在回显时通过表单发送不正确的 POST 数据?
我正在编写一个简单的注册表单来将用户添加到数据库中。代码如下。
<?php
include 'header.php';
$tag = randomString();
?>
<html>
<head>
<title>Register an Account</title>
</head>
<body>
<b>Register an account</b><br><br>
<form method="post" action="add_user.php?tag=<?echo $tag;?>">
Username: <br><input type="text" name="username" size=25/><br /><br>
Password: <br><input type="password" name="password" size=25/><br /><br>
Confirm Password: <br><input type="password" name="confirm" size=25/><br /><br>
Email Address: <br><input type="text" name="email" size=25/><br /><br><br>
Additional Info: <br><input type="text" name="info" size=50/><br>
<input type="submit" name="Submit" />
</form>
</body>
</html>
该表格似乎运行良好。但是,当我尝试阅读下一页上的此帖子数据时,即使所有条目都已填满,某些条目是正确的,而其他条目则不正确。例如:
echo mysql_real_escape_string(htmlentities($_POST['username'])); --> outputs what was in the info field
echo mysql_real_escape_string(htmlentities($_POST['password'])); --> output is what was entered in "confirm"
echo mysql_real_escape_string(htmlentities($_POST['confirm'])); --> no output
echo mysql_real_escape_string(htmlentities($_POST['email'])); --> email is outputted, this is correct.
echo mysql_real_escape_string(htmlentities($_POST['info'])); --> No output.
很困惑为什么会发生这种情况,我写了很多表格,没有出现这样的问题。
编辑:这是var_dump(输入的数据:用户名、Pass1、Pass2、[email protected]< /a>,以及按正确顺序排列的信息):
array(4) { ["username"]=> string(4) "info" ["password"]=> string(5) "Pass2" ["email"]=> string(17) "[email protected]" ["Submit"]=> string(6) "Submit" }
编辑2:添加了整个页面的代码
add_user.php (未完成 - 当我尝试比较两个密码时出现了问题。这从未被评估为 true,主要是因为我没有比较我的内容我以为是)
<?php
//var_dump($_POST);
echo mysql_real_escape_string(htmlentities($_POST['username'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['password'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['confirm'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['email'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['info'])); echo "<br>";
if ($_POST['password'] != $_POST['confirm']) {
die("Passwords do not match. Please go back and try again.");
}
$tag = $_GET['tag'];
?>
I'm writing a simple registration form to add users to a database. The code is below.
<?php
include 'header.php';
$tag = randomString();
?>
<html>
<head>
<title>Register an Account</title>
</head>
<body>
<b>Register an account</b><br><br>
<form method="post" action="add_user.php?tag=<?echo $tag;?>">
Username: <br><input type="text" name="username" size=25/><br /><br>
Password: <br><input type="password" name="password" size=25/><br /><br>
Confirm Password: <br><input type="password" name="confirm" size=25/><br /><br>
Email Address: <br><input type="text" name="email" size=25/><br /><br><br>
Additional Info: <br><input type="text" name="info" size=50/><br>
<input type="submit" name="Submit" />
</form>
</body>
</html>
The form seems to work fine. However, when I attempt to read this post data on the next page, some entries are correct, and others are not, even when all entries are filled. For example:
echo mysql_real_escape_string(htmlentities($_POST['username'])); --> outputs what was in the info field
echo mysql_real_escape_string(htmlentities($_POST['password'])); --> output is what was entered in "confirm"
echo mysql_real_escape_string(htmlentities($_POST['confirm'])); --> no output
echo mysql_real_escape_string(htmlentities($_POST['email'])); --> email is outputted, this is correct.
echo mysql_real_escape_string(htmlentities($_POST['info'])); --> No output.
Very confused as to why this is happening, I've written many forms with no such problems.
EDIT: Here's the var_dump (data entered: username, Pass1, Pass2, [email protected], and info in the proper order):
array(4) { ["username"]=> string(4) "info" ["password"]=> string(5) "Pass2" ["email"]=> string(17) "[email protected]" ["Submit"]=> string(6) "Submit" }
EDIT2: Added entire page's code
add_user.php (Not finished-- the issue came up when I was trying to compare the two passwords. That never evaluated as true, mainly because I wasn't comparing what I thought I was)
<?php
//var_dump($_POST);
echo mysql_real_escape_string(htmlentities($_POST['username'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['password'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['confirm'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['email'])); echo "<br>";
echo mysql_real_escape_string(htmlentities($_POST['info'])); echo "<br>";
if ($_POST['password'] != $_POST['confirm']) {
die("Passwords do not match. Please go back and try again.");
}
$tag = $_GET['tag'];
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中 $_POST 根本不是值“confirm”和“info”。这就是为什么他们不输出任何东西。
我建议打开 PHP 的通知,他们会立即告知这一点。
我不认为您填错了表格。因为“info”是“username”的值。
In that $_POST is not values "confirm" and "info" at all. That’s why they don’t output anything.
I suggest to switch PHP’s notices on, they would tell this instantly.
I can’t think but that you have filled the form wrong. Since ”info” is value of “username”.