1
我正在寫一個簡單的註冊表單來將用戶添加到數據庫。代碼如下。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(輸入的數據:用戶名,1步,2步,[email protected],並以正確的順序信息):
array(4) { ["username"]=> string(4) "info" ["password"]=> string(5) "Pass2" ["email"]=> string(17) "[email protected]" ["Submit"]=> string(6) "Submit" }
EDIT2:增加了整個頁面的代碼
add_user.php(不finished--問題出來了,當我試圖將兩個密碼相比較,這不會求真實,主要是因爲我沒有什麼比較,我想我是)
<?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'];
?>
如何測試一個簡單的'var_dump($ _ POST)'? – deceze
這很有趣。 'mysql_real_escape_string'不應該輸出任何東西。 'htmlentities'也不應該。 – Oswald
添加了var_dump。只是爲了澄清,這些陳述都回應,但是當我在這裏粘貼代碼時,我忘記了回聲陳述。 – aerotwelve