你好,所以我的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");
}
}
答案 0 :(得分: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");
答案 1 :(得分: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");
}
}