我有一个HTML页面,上面有一个简单的表单,可以将数据提交给login.php。在login.php里面我有这个代码。当我尝试执行此脚本时,我收到此错误:
解析错误:语法错误,第13行/home/login.php中的意外T_VARIABLE
<?php
$username = $_POST['login'];
$password = $_POST['password'];
if ($username&&$password) {
$connect = mysql_connect("localhost", "admin", "1455m") or die("Couldn't Connect");
mysql_select_db("lr") or die("Couldn't find database!");
$query = mysql_query("SELECT * FROM users WHERE username='$username'")
$numrows = mysql_num_rows($query);
if ($numrows!=0) {
while ($row = mysql_fetch_assoc($query)) {
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword) {
echo 'You are In!';
} else {
echo 'Incorrect Password!';
}
} else {
die("That user doesn't exist.");
}
} else {
die("Please enter a username & password.");
}
?>
答案 0 :(得分:9)
你错过了一个分号:
$query = mysql_query("SELECT * FROM users WHERE username='$username'")
^
Here
答案 1 :(得分:3)
该错误告诉您第13行的某些内容是意料之外的;在这种情况下是一个变量。因此,通常最好检查前面的代码并检查它在语法上是否正确。
在这种情况下,你在第13行的行中错过了一个分号,因此你的格式是第11行 - 就在你使用mysql_query()的地方!试试这个......
$connect = mysql_connect("localhost", "admin", "1455m") or die("Coudn't Connect");
mysql_select_db("lr") or die("Coudn't find database!");
$query = mysql_query("SELECT * FROM users WHERE username='$username'"); // here!
$numrows = mysql_num_rows($query);
答案 2 :(得分:-2)
您忘记在查询中添加连接:
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
应该是:
$result = mysql_query("SELECT * FROM users WHERE username='$username'", $connect);