我是一個初學PHP編碼器。我希望它是如果當他們註冊我的PHP代碼時,它回聲「你已經註冊」,而不是隻顯示一個空白頁。這是我的代碼:MySQL和PHP Basic Form Echo
<?php
require('config.php');
if(isset($_POST['submit'])){
//Preform the verification of the nation
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2) {
if($pass1 == $pass2) {
//All good. Carry on.
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($_POST['email1']);
$email2 = mysql_escape_string($_POST['email2']);
$pass1 = mysql_escape_string($_POST['pass1']);
$pass2 = mysql_escape_string($_POST['pass2']);
$pass1 = md5($pass1);
$sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname'");
if(mysql_num_rows($sql) > 0) {
echo "Sorry, that user already exists!";
exit();
}
mysql_query("INSERT INTO `users` (`id`, `name`, `lname`, `uname`, `email`,
`pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1',
'$pass1')");
}else{
echo "Sorry, your passwords do not match<br><br>";
exit();
}
}else{
echo "Sorry, your emails do not match.<br><br>";
}
}else{
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="pass1" /><br />
Confirm Password: <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;
}
?>
正如你所看到的,如果一切正常,沒有回聲。請幫助我添加一個回聲,如果他們的註冊登記!
提示:不要檢查是否存在表單字段以確定是否發生了帖子。這是不可靠的。改用'if($ _SERVER ['REQUEST_METHOD'] =='POST'){...}'代替。它是100%可靠的,永遠不會讓你失望。 –
順便說一下,md5不是創建「安全」用戶密碼的方法。這是一種便宜的方式,很容易解密。請檢查使用[PHPass](http://www.openwall.com/phpass/)這將確保一個更安全的環境。不要學習困難的方式 – ntgCleaner
確保它被插入到數據庫中,然後顯示消息! – meWantToLearn