0

您好,所以我的 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");
    }
}
4

2 回答 2

1

你有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");
于 2013-05-23T12:09:41.883 回答
0

你必须使用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");
  }
}
于 2013-05-23T12:10:58.517 回答