PHP括号错误问题


PHP Brackets error trouble

你好,所以我的PHP脚本给了我一个错误,在我的if语句上的右括号错误如下,这极大地阻碍了我,任何帮助将不胜感激,谢谢。

解析错误:语法错误,第40行出现意外T_ELSE

if($numrows !=0) {
    while ($rows = mysql_fetch_assoc($query)) {
        $dbusername = $row['username'];
        $dbpassword = $row['password'];
    }
    if ($username==$dbusername&&$password==dbpassword) {
        echo "Login Successful. <a href='homepage.html'>Click Here to go to the home page</a>";
        $_SESSION['username']=$dbusername;
    }
    else {
        echo "Incorrect Login";
    }
    else {
        die ("This account does not exsist");
    }
    else {
        die ("Please enter a username and password");
    }
}

你有3 else,我只看到2 if

在需要的地方尝试else if (condtion){ },或者简单地将所有代码放在单个else中。

目前,这些else没有匹配的if,生成Parse error: syntax error, unexpected T_ELSE on line 40

else{
die ("This account does not exsist");
    }
else{
die ("Please enter a username and password");

必须使用elseif

请通过:http://php.net/manual/en/control-structures.elseif.php

例如:

if ($numrows != 0) {
  while ($rows = mysql_fetch_assoc($query)) {
    $dbusername = $row['username'];
    $dbpassword = $row['password'];
  }
  if ($username == $dbusername && $password == dbpassword) {
    echo "Login Successful. <a href='homepage.html'>Click Here to go to the home page</a>";
    $_SESSION['username'] = $dbusername;
  } elseif ($username == '' || $password == '') {
    die("Please enter a username and password");
  } elseif (empty($dbusername)) {
    die("This account does not exsist");
  } else {
    die("Please enter a username and password");
  }
}