2015-11-25 47 views
0

警告:mysql_num_rows()期望參數1是資源,布爾在第16行給出 您的登錄會話數據未記錄在數據庫中。mysql_num_rows()期望參數1是資源,PHP中的布爾錯誤消息

當我想登錄到我的網站的管理區域時出現此錯誤。我不知道爲什麼會發生,因爲一切看起來都很棒!

<?php 
session_start(); 
if (!isset($_SESSION["manager"])) { 
    header("location: index.php"); 
    exit(); 
} 
// Be sure to check that this manager SESSION value is in fact in the database 
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters 
$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters 
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters 
// Run mySQL query to be sure that this person is an admin and that their password session var equals the database information 
// Connect to the MySQL database 
include "inc/connect.php"; 
$sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person 
// ------- MAKE SURE PERSON EXISTS IN DATABASE --------- 
$existCount = mysql_num_rows($sql); // count the row nums 
if ($existCount == 0) { // evaluate the count 
    echo "Your login session data is not on record in the database."; 
    exit(); 
} 
?> 

這是第16行:

$existCount = mysql_num_rows($sql); // count the row nums 

正如你可以看到,我把這個$ existCount,看看是否有對數據庫沒有記錄,但 居然有上分貝所以這一塊的一些記錄不應該彈出...

如果您對這個問題有任何想法,請讓我知道!

+0

'mysql_ *'已棄用,請使用'mysqli_ *'或'PDO'。 –

+0

明文密碼?!?僅限於字母數字字符?!? –

+0

這裏有什麼>>> connect.php –

回答

0

確保在mysql_query()返回後檢查錯誤。錯誤消息指示mysql_query()未返回有效的資源,這意味着它失敗。 mysql_error()會告訴你爲什麼。

作爲一般規則,在執行可能失敗的操作時,應始終檢查錯誤返回值。

相關問題