我对SQL和PHP相当陌生。PHP登录脚本SQL错误
我想写一个简单的登录脚本。我有一个HTML文档中的表单,我已经证明在2个变量中需要正确的数据,但是我的脚本在执行SQL时失败了...
我也测试了mysqlWorkbench中的SQL,我想要的结果?
请帮忙。
这里是我的脚本:
<?PHP
$odbc = mysql_connect('localhost', 'root', '') or die ("could not connect to database");
mysql_select_db('examresults', $odbc) or die("Could not find database");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
$sql='SELECT * FROM tuser where username = '.$username.' and password = '.$password.'';
$result = mysql_query($sql, $odbc) or die ("Error in SQL");
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
//If result matched username and password, table row must only equal 1 row
if($count==1)
{
header("location:exammenu.php");
}
else
{
echo 'username and password do not match';
}
?>
如果您是新手,我建议您停止使用mysql_connect,并且(如果您熟悉),请改为使用mysqli。 http://www.php.net/manual/en/function.mysql-connect.php – Lucas
我必须使用MySQL的 – Matt
你什么错误? – Lucas