PHP - 回显时通过表单发送的 POST 数据不正确?

标签 php mysql forms postdata

我正在编写一个简单的注册表以将用户添加到数据库中。代码如下。

<?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@address.com 和正确顺序的信息):

array(4) { ["username"]=> string(4) "info" ["password"]=> string(5) "Pass2" ["email"]=> string(17)     "email@address.com" ["Submit"]=> string(6) "Submit" }

EDIT2:添加了整个页面的代码

add_user.php(未完成——当我尝试比较两个密码时出现了这个问题。从未评估为真,主要是因为我没有比较我认为的)

<?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'];
?>

最佳答案

因为 $_POST 根本不是值“confirm”和“info”。这就是为什么他们不输出任何东西。

我建议打开 PHP 的通知,他们会立即告知。

我不能认为你填错了表格。因为“info”是“username”的值。

关于PHP - 回显时通过表单发送的 POST 数据不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880017/

相关文章:

PHPStorm 缺少返回语句

php - 存储 HABTM 协会中持有的项目的排序顺序 - CakePHP

php - 如何在 MySQL 中查找所有子行?

php - Symfony 2.8 文件上传 "Cannot read index ".. ."from object of type because Entity doesn' t 实现 ArrayAccess。”

javascript - JQuery 函数submit(),用于当用户在 input=text 中按 Enter 时,还提交位于同一表单中的 input=submit

选中多个复选框时的 javascript 代码应根据复选框显示表单字段(我使用选择选项方法尝试过)

php - Doctrine/Symfony 乱序生成迁移

php - 在 PHP 中使用 session_name() - 无法访问数据

php - preg_replace (#\s+#) 的简单模式的含义?

mysql - Bash MySQL 查询