Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql_num_rows()希望参数1是PHP中的资源、布尔错误消息_Php_Mysql - Fatal编程技术网

mysql_num_rows()希望参数1是PHP中的资源、布尔错误消息

mysql_num_rows()希望参数1是PHP中的资源、布尔错误消息,php,mysql,Php,Mysql,警告:mysql\u num\u rows()希望参数1是资源,布尔值在第16行给出 您的登录会话数据未记录在数据库中。 当我想登录到我的站点的管理区域时,会出现此错误。我不知道为什么会这样,因为一切看起来都很棒 <?php session_start(); if (!isset($_SESSION["manager"])) { header("location: index.php"); exit(); } // Be sure to check that t

警告:mysql\u num\u rows()希望参数1是资源,布尔值在第16行给出 您的登录会话数据未记录在数据库中。

当我想登录到我的站点的管理区域时,会出现此错误。我不知道为什么会这样,因为一切看起来都很棒

    <?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();
}
?>
如您所见,我将$existCount放在数据库中,以查看数据库中是否没有记录,但 事实上,数据库中有一些记录,所以这个记录不应该弹出


如果你对这个问题有任何想法,请告诉我

确保在
mysql\u query()
返回后检查错误。错误消息表明
mysql\u query()
没有返回有效的资源,这意味着它失败了
mysql\u error()
将告诉您原因


一般来说,在执行可能失败的操作时,您应该始终检查错误返回值。

mysql.*
不推荐使用,请使用
mysqli.*
PDO
。明文密码?!?而且只限于字母数字字符?!?这里有什么>>>connect.phpand不检查查询中的错误,也不检查PHP中的错误
$existCount = mysql_num_rows($sql); // count the row nums