-2

我正在尝试使 php 注册表单正常工作,但我遇到了 if/else 语句的问题。但无法完全弄清楚。

ERROR: Parse error: syntax error, unexpected 'if' (T_IF) in E:\xampp\htdocs\test\register.php on line 21

PHP代码:

$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$email = $_POST['email'];

if ($username && $password && $repassword  && $email)
{
        if ($password == $repassword)
        {
            include ("connect.php");
            $query = mysql_query("SELECT * FROM users WHERE username = '$username'");
            $numrows = mysql_num_rows($query)
            if($numrows == 0)         <<- LINE 21
            {
                echo "Username not taken";
            }
            else
            {
                echo "That username is taken!";
            }
        }
        else
            echo "Password did not match";  }
else
    echo "You did not fill in every field!";

else {//show registration form Stackoverflow cant display it properly.}

也许你们中的一个人看到了这个问题。

提前致谢,

吉姆

4

3 回答 3

5

;您在查询后立即缺少分号

$numrows = mysql_num_rows($query); //here is missing wich is causing the error

正如 Kavi Siegel 所建议的那样进行编辑,您似乎在最后一个 else 中也缺少一个右括号(您拥有的那个已被评论)

else 
{//show registration form Stackoverflow cant display it properly.


} //this was commented
于 2013-05-15T12:53:40.663 回答
2

关闭你的If Conditions正确。

if ($username && $password && $repassword  && $email)
{
        if ($password == $repassword)
        {
            include ("connect.php");
            $query = mysql_query("SELECT * FROM users WHERE username = '$username'");
            $numrows = mysql_num_rows($query)
            if($numrows == 0)         <<- LINE 21
            {
                echo "Username not taken";
            }
            else
            {
                echo "That username is taken!";
            }
        } else {
            echo "Password did not match";  }
 } else
    echo "You did not fill in every field!";
于 2013-05-15T12:53:33.820 回答
0

在此之后加上分号

$numrows = mysql_num_rows($query)

改成这个

$numrows = mysql_num_rows($query);
于 2013-05-15T12:53:45.810 回答