我为登录页面写了一小段代码。代码如下:
if($user == "" || $pass == "")
{
echo "Please fill in all the information!";
}
//Check to see if the username AND password MATCHES the username AND password in the DB
else
{
$query = mysqli_query($con,"SELECT * FROM members WHERE username = '$user' and password = '$pass'") or die("Can not query DB.");
$count = mysqli_num_rows($query);
if ($count == 1)
{
$_SESSION['username']=$user; //Create a session for the user!
header ("location: members.php");
}
else{
echo "Username and Password DO NOT MATCH! TRY AGAIN!";
}
}
我无法运行我的脚本,它返回以下错误:
PHP Parse错误:语法错误,第38行/var/www/user/login.php中的意外'if'(T_IF)(第二个“if”)
答案 0 :(得分:2)
您的脚本中似乎有奇怪的字符。当我删除code you pasted中的缩进时,会在下一行中报告语法错误。
在违规行之前,缩进中有一个“不间断空格”字符(代码160,0xa0)。这是第36到38行看起来如何看到可见的空白区域:
36: \t\t$count = mysqli_num_rows($query);\n 37: \t\xa0\t\n ^^^^ Non-breaking Space 38: \t\tif ($count == 1) \n
用常规空格替换它,你的代码应该运行。
奇怪的是,PHP在下一个令牌上窒息而不是抱怨源中存在无效字符。