1

我是初学者 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;
   }
?>

如您所见,如果一切正常,则没有回声。如果他们的注册被注册,请帮我添加回声!

4

3 回答 3

0

before the last

}else{

in your code put

echo "You have signed up";

and that's it :)

于 2012-06-28T02:23:12.237 回答
0

只需检查插入查询的返回。

$result = mysql_query("INSERT ...");
if ($result) {
    echo "Created!";
} else {
    echo "Uh oh!  Something went wrong!";
}
于 2012-06-26T03:50:42.283 回答
0

在你的情况下 - 你可以输入:

echo "Congratulations, You've been submitted";

或者你想说的就在插入语句下

于 2012-06-26T03:58:13.733 回答