Username: Password: -6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:36:33 26 4
gpt4 key购买 nike

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

<?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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com