php注册表单中的T_IF错误

时间:2013-05-15 12:52:17

标签: php

我正在尝试使用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.}

Maby你们其中一个人看到了这个问题。

提前完成,

吉姆

3 个答案:

答案 0 :(得分:5)

您的查询后面缺少分号;

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

编辑,因为Kavi Siegel建议你似乎也错过了最后一个结束(你得到的那个被评论)

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


} //this was commented

答案 1 :(得分: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!";

答案 2 :(得分:0)

在此之后加上分号

$numrows = mysql_num_rows($query)

将其更改为此

$numrows = mysql_num_rows($query);