我是一名初学者PHP编码器。我希望它是如果他们注册我的PHP代码,它回声“你已经注册”,而不是只显示一个空白页。这是我的代码:
<?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;
}
?>
正如你所看到的,如果一切正常,就没有回音。如果注册登记,请帮助我添加一个回音!!
答案 0 :(得分:0)
只需检查插入查询的返回值。
$result = mysql_query("INSERT ...");
if ($result) {
echo "Created!";
} else {
echo "Uh oh! Something went wrong!";
}
答案 1 :(得分:0)
在您的情况下 - 您只需输入:
echo "Congratulations, You've been submitted";
或者你想在插入声明下说什么
答案 2 :(得分:0)
在最后一次
之前}else{
在您的代码中
echo "You have signed up";
就是这样:))