Copy link to clipboard
Copied
I am getting these warnings on one of my pages:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\WFRMA\Admin\update.php on line 126
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\WFRMA\Admin\update.php on line 147
I commented out the lines to see if they are in fact where the problem lies. I didn't receive the errors after doing this so the line references appear to be accurate. I've been unable to figure out how to fix this though. The script seems to run just fine even with this warning, but I would like to correct whatever is happening and grateful for any help getting me on the right track.
Local server: XAMPP version 2.5.8
PHP 5.3.1
MySQL 5.1.41
phpMyAdmin 3.2.4
Apache 2.2.14
Workstation OS: Win XP Pro SP3
Marking thread as "assumed answered".
Copy link to clipboard
Copied
I dont know how anyone would be able to tell without seeing lines 126 and 147.
Gary
Copy link to clipboard
Copied
These are the two lines in question:
#126: $totalRows_rsUsers = mysql_num_rows($all_rsUsers);
#147: $totalRows_rsDirectory = mysql_num_rows($all_rsDirectory);
Copy link to clipboard
Copied
I'm sorry, I should have said to post all of your code, however, that type of error is sometimes the result of MySQL being unable to process the SQL you provided it, so you need to check the query code. Check to see if the result of your mysql_query() is false, and if so, do an error_log() or otherwise output the query string and the result of mysql_error() to find out what was wrong with the query.
If that does not work, post all of your code.
Gary
Copy link to clipboard
Copied
In the interests of time, I'm going ahead and posting all of the php code while I also look into your troubleshooting tips. Appreciate it.
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_rsUsers = 20;
$pageNum_rsUsers = 0;
if (isset($_GET['pageNum_rsUsers'])) {
$pageNum_rsUsers = $_GET['pageNum_rsUsers'];
}
$startRow_rsUsers = $pageNum_rsUsers * $maxRows_rsUsers;
mysql_select_db($database_wfrma, $wfrma);
$query_rsUsers = "SELECT user_id, first_name, last_name, username, email FROM users ORDER BY last_name ASC";
$query_limit_rsUsers = sprintf("%s LIMIT %d, %d", $query_rsUsers, $startRow_rsUsers, $maxRows_rsUsers);
$rsUsers = mysql_query($query_limit_rsUsers, $wfrma) or die(mysql_error());
$row_rsUsers = mysql_fetch_assoc($rsUsers);
if (isset($_GET['totalRows_rsUsers'])) {
$totalRows_rsUsers = $_GET['totalRows_rsUsers'];
} else {
$all_rsUsers = mysql_query($query_rsUsers);
$totalRows_rsUsers = mysql_num_rows($all_rsUsers);
}
$totalPages_rsUsers = ceil($totalRows_rsUsers/$maxRows_rsUsers)-1;
$maxRows_rsDirectory = 20;
$pageNum_rsDirectory = 0;
if (isset($_GET['pageNum_rsDirectory'])) {
$pageNum_rsDirectory = $_GET['pageNum_rsDirectory'];
}
$startRow_rsDirectory = $pageNum_rsDirectory * $maxRows_rsDirectory;
mysql_select_db($database_wfrma, $wfrma);
$query_rsDirectory = "SELECT directory_id, first_name, last_name, affiliation FROM directory ORDER BY last_name ASC";
$query_limit_rsDirectory = sprintf("%s LIMIT %d, %d", $query_rsDirectory, $startRow_rsDirectory, $maxRows_rsDirectory);
$rsDirectory = mysql_query($query_limit_rsDirectory, $wfrma) or die(mysql_error());
$row_rsDirectory = mysql_fetch_assoc($rsDirectory);
if (isset($_GET['totalRows_rsDirectory'])) {
$totalRows_rsDirectory = $_GET['totalRows_rsDirectory'];
} else {
$all_rsDirectory = mysql_query($query_rsDirectory);
$totalRows_rsDirectory = mysql_num_rows($all_rsDirectory);
}
$totalPages_rsDirectory = ceil($totalRows_rsDirectory/$maxRows_rsDirectory)-1;
$maxRows_rsAdmin = 10;
$pageNum_rsAdmin = 0;
if (isset($_GET['pageNum_rsAdmin'])) {
$pageNum_rsAdmin = $_GET['pageNum_rsAdmin'];
}
$startRow_rsAdmin = $pageNum_rsAdmin * $maxRows_rsAdmin;
mysql_select_db($database_wfrmaread, $wfrmaread);
$query_rsAdmin = "SELECT * FROM `admin`";
$query_limit_rsAdmin = sprintf("%s LIMIT %d, %d", $query_rsAdmin, $startRow_rsAdmin, $maxRows_rsAdmin);
$rsAdmin = mysql_query($query_limit_rsAdmin, $wfrmaread) or die(mysql_error());
$row_rsAdmin = mysql_fetch_assoc($rsAdmin);
if (isset($_GET['totalRows_rsAdmin'])) {
$totalRows_rsAdmin = $_GET['totalRows_rsAdmin'];
} else {
$all_rsAdmin = mysql_query($query_rsAdmin);
$totalRows_rsAdmin = mysql_num_rows($all_rsAdmin);
}
$totalPages_rsAdmin = ceil($totalRows_rsAdmin/$maxRows_rsAdmin)-1;
$queryString_rsUsers = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsUsers") == false &&
stristr($param, "totalRows_rsUsers") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsUsers = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsUsers = sprintf("&totalRows_rsUsers=%d%s", $totalRows_rsUsers, $queryString_rsUsers);
$queryString_rsDirectory = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsDirectory") == false &&
stristr($param, "totalRows_rsDirectory") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsDirectory = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsDirectory = sprintf("&totalRows_rsDirectory=%d%s", $totalRows_rsDirectory, $queryString_rsDirectory);
?>
Copy link to clipboard
Copied
One of the sections of code that's generating the error looks like this:
mysql_select_db($database_wfrma, $wfrma); $query_rsDirectory = "SELECT directory_id, first_name, last_name, affiliation FROM directory ORDER BY last_name ASC";
$query_limit_rsDirectory = sprintf("%s LIMIT %d, %d", $query_rsDirectory, $startRow_rsDirectory, $maxRows_rsDirectory);
$rsDirectory = mysql_query($query_limit_rsDirectory, $wfrma) or die(mysql_error());
$row_rsDirectory = mysql_fetch_assoc($rsDirectory);if (isset($_GET['totalRows_rsDirectory'])) {
$totalRows_rsDirectory = $_GET['totalRows_rsDirectory'];
} else {
$all_rsDirectory = mysql_query($query_rsDirectory);
$totalRows_rsDirectory = mysql_num_rows($all_rsDirectory);
}
As you can see in the final line, $all_rsDirectory is being passed to mysql_num_rows(). The error message says that a Boolean is being passed. In other words, $all_rsDirectory is either TRUE or FALSE.
You can see from the preceding line that $all_rsDirectory is created by passing $query_rsDirectory to mysql_query(). Look a bit further up, and you'll see that $query_rsDirectory is the SQL query. In other words, the PHP code looks fine.
If you consult the PHP manual for mysql_query(), you'll see that it returns a database resource on success, and FALSE on failure. Consequently, it appears there's something wrong with your database connection or query.
One way to find out is to change this:
$all_rsDirectory = mysql_query($query_rsDirectory);
to this:
$all_rsDirectory = mysql_query($query_rsDirectory) or die(mysql_error());
That will tell you if there's an error in the SQL, although it doesn't look as though there is.
Copy link to clipboard
Copied
Thanks David. I can't tell you how helpful that thought process and detailed explanation is to someone like me of limited skills in this area. I'll look into it further.
Copy link to clipboard
Copied
I changed the $all_rsDirectory code as you suggested. The result was this message:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\WFRMA\Admin\update.php on line 126
No database selected
I didn't get the page to display at all this time as it did before (with the warning messages at the top). Just a page with this latest warning. Can you help me decipher this and what my next step might be?
Peter
Copy link to clipboard
Copied
My issue is resolved. I went back into the server behaviors in DW and when I clicked on the main recordsets I was getting error messages. I went back into them and ran a test and closed out. That generated new code which I replaced the old code with and everything seems to be working fine now. Why things got out of whack is beyond me unfortunately. However I am relieved to have isolated and fixed the problem. Many thanks again for the help on this.
Copy link to clipboard
Copied
Marking thread as "assumed answered".
Find more inspiration, events, and resources on the new Adobe Community
Explore Now