2011-07-29 6 views
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. 

これが起こっている理由として非常に混乱し、私はそのような問題を持つ多くの形態を書いています。

EDIT:

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

EDIT2:追加されましたページ全体のコード

ここのvar_dumpは(:ユーザ名、パス1、パス2、[email protected]、および適切な順序で情報データが入力された)ですadd_user.php(私は2つのパスワードを比較しようとしていた時に問題が思い付いた。真と評価されないことを、私は私が思ったものを比較していなかった主な理由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']; 
?> 
+6

テストのための単純な 'var_dump($ _ POST)'はどうでしょうか? – deceze

+2

これは興味深いです。 mysql_real_escape_stringは何も出力しません。どちらも 'htmlentities'ではありません。 – Oswald

+0

var_dumpを追加しました。そして、これらのステートメントはすべてエコーされていますが、ここでコードを貼り付けると、エコーステートメントを忘れてしまいました。 – aerotwelve

答えて

0

$ _POSTは "confirm"と "info"という値ではありません。だから彼らは何も出力しません。

私は、PHPの通知を切り替えることをお勧めします。

私は考えることができませんが、フォームを間違って入力しました。 "info"は "username"の値ですから。

関連する問題