0
我正在進行登錄,並在計算MySQL查詢的行數時出現錯誤。錯誤在下面。計數行時出錯
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/nzcraftn/public_html/bs/login.php on line 13
Warning: Cannot modify header information - headers already sent by (output started at /home/nzcraftn/public_html/bs/login.php:13) in /home/nzcraftn/public_html/bs/login.php on line 21
我使用此代碼進行登錄。
<?php
session_start();
include('config.php');
$user = protect($_POST['username']);
$pass = protect($_POST['password']);
$salt = "a123b123";
$thepass = md5($salt.md5($pass));
$res = mysql_query("SELECT `username`,`password` WHERE (`username` = '$user' AND `password` = '$thepass')");
$count = mysql_num_rows($res);
if($count == 1) {
$_SESSION['user'] = $user;
print($_SESSION['user']);
//header('Location: /panel/index.php');
} else {
$_SESSION['errormsg'] = "<div style='color: #FF0000'>Invalid Login!</div>";
header('Location: index.php');
}
?>
錯誤是不言自明的; 'mysql_query'返回false,因爲你沒有給它一個有效的查詢。您沒有指定要從哪個表中選擇。你不能用'false'來計算行數。 –
[mysql_fetch_array()的可能重複期望參數1是資源,布爾在給出](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource - 布爾賜予的,在選) – legoscia