Warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result res

I’m receiving the following errors suddenly:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 102

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 129

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 150

The code has worked in the past and was never changed. The code refers to the following:

  1. $totalRows_getHHH = mysql_num_rows($all_getHHH);

  2. $totalRows_getEvents = mysql_num_rows($all_getEvents);

  3. $totalRows_getNews = mysql_num_rows($all_getNews);

I’m rather confused since this has worked in the past.

The complete request:

$maxRows_getHHH = 4;
$pageNum_getHHH = 0;
if (isset($_GET['pageNum_getHHH'])) {
  $pageNum_getHHH = $_GET['pageNum_getHHH'];
}
$startRow_getHHH = $pageNum_getHHH * $maxRows_getHHH;

mysql_select_db($database_Tr_L349, $Tr_L349);
$query_getHHH = "SELECT hth_id, heading FROM how_to_help";
$query_limit_getHHH = sprintf("%s LIMIT %d, %d", $query_getHHH, $startRow_getHHH, $maxRows_getHHH);
$getHHH = mysql_query($query_limit_getHHH, $Tr_L349) or die(mysql_error());
$row_getHHH = mysql_fetch_assoc($getHHH);

if (isset($_GET['totalRows_getHHH'])) {
  $totalRows_getHHH = $_GET['totalRows_getHHH'];
} else {
  $all_getHHH = mysql_query($query_getHHH);
  $totalRows_getHHH = mysql_num_rows($all_getHHH);
}
$totalPages_getHHH = ceil($totalRows_getHHH/$maxRows_getHHH)-1;

mysql_select_db($database_Tr_L349, $Tr_L349);
$query_getBS = "SELECT books_on_sale.teaser, books_on_sale.book, books_on_sale.author, books_on_sale.image  FROM books_on_sale ORDER BY books_on_sale.book";
$getBS = mysql_query($query_getBS, $Tr_L349) or die(mysql_error());
$row_getBS = mysql_fetch_assoc($getBS);
$totalRows_getBS = mysql_num_rows($getBS);

$maxRows_getEvents = 5;
$pageNum_getEvents = 0;
if (isset($_GET['pageNum_getEvents'])) {
  $pageNum_getEvents = $_GET['pageNum_getEvents'];
}
$startRow_getEvents = $pageNum_getEvents * $maxRows_getEvents;

mysql_select_db($database_Tr_L349, $Tr_L349);
$query_getEvents = "SELECT event_id, event, day_time FROM events";
$query_limit_getEvents = sprintf("%s LIMIT %d, %d", $query_getEvents, $startRow_getEvents, $maxRows_getEvents);
$getEvents = mysql_query($query_limit_getEvents, $Tr_L349) or die(mysql_error());
$row_getEvents = mysql_fetch_assoc($getEvents);

if (isset($_GET['totalRows_getEvents'])) {
  $totalRows_getEvents = $_GET['totalRows_getEvents'];
} else {
  $all_getEvents = mysql_query($query_getEvents);
  $totalRows_getEvents = mysql_num_rows($all_getEvents);
}
$totalPages_getEvents = ceil($totalRows_getEvents/$maxRows_getEvents)-1;

$maxRows_getNews = 3;
$pageNum_getNews = 0;
if (isset($_GET['pageNum_getNews'])) {
  $pageNum_getNews = $_GET['pageNum_getNews'];
}
$startRow_getNews = $pageNum_getNews * $maxRows_getNews;

mysql_select_db($database_Tr_L349, $Tr_L349);
$query_getNews = "SELECT news_id, date_pub, title, link FROM news ORDER BY news_id DESC";
$query_limit_getNews = sprintf("%s LIMIT %d, %d", $query_getNews, $startRow_getNews, $maxRows_getNews);
$getNews = mysql_query($query_limit_getNews, $Tr_L349) or die(mysql_error());
$row_getNews = mysql_fetch_assoc($getNews);

if (isset($_GET['totalRows_getNews'])) {
  $totalRows_getNews = $_GET['totalRows_getNews'];
} else {
  $all_getNews = mysql_query($query_getNews);
  $totalRows_getNews = mysql_num_rows($all_getNews);
}
$totalPages_getNews = ceil($totalRows_getNews/$maxRows_getNews)-1;

Do you see anything I’m missing?

You’re getting them errors because the queries they relate to have failed for whatever reason, have any changes been made to the table structure?

Is php connecting to and selecting the database ok?

Nothing has been changed to the table structure and everything works great! All of the information is posting from the dbase table just fine.

It’s a queer thing. We haven’t touched this system. It’s one of those things that just popped up!

It could have been some kind of hiccup in network traffic (if the database is on a different machine).

It’s also possible that the database couldn’t run for some reason. I know we had a problem on one of our dev servers the other day where someone had uploaded a bunch of ISOs to the server and took up all the memory. The database wasn’t able to run properly because of that.

If you have temp files stored on the server, it could have been the temp files took up all the space, but when they were cleared out it started working again.

Hiccup or not, it’s sure annoying. I went on ahead and set up a bypass so it wouldn’t show up on the website anymore. Other than that, the code works great!

Thanks for the help!

I’m having the same problem…

code is working fine but there are times this kind of error appears on my site…

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 102

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 129

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/97/6031597/html/index.php on line 150

please explain me clearly why is it happening… is it a problem with the code?

Thanks

You need to show your code since it is rare that two sites will have the same problem with the same cause (unless they’re using the same script).


$sql = '';
$set_karma = unserialize($set['karma']);
if ($user_id) {
    
    if (!$datauser['karma_off'] && $set_karma['on'] && $datauser['karma_time'] <= ($realtime - 86400)) {
        $sql = "`karma_time` = '$realtime', ";
    }
    $movings = $datauser['movings'];
    if ($datauser['lastdate'] < ($realtime - 300)) {
        $movings = 0;
        $sql .= "`sestime` = '$realtime',";
    }
    if ($datauser['place'] != $headmod) {
        $movings = $movings + 1;
        $sql .= "`movings` = '$movings', `place` = '$headmod',";
    }
    if ($datauser['browser'] != $agn)
        $sql .= "`browser` = '" . mysql_real_escape_string($agn) . "',";
    $totalonsite = $datauser['total_on_site'];
    if ($datauser['lastdate'] > ($realtime - 300))
        $totalonsite = $totalonsite + $realtime - $datauser['lastdate'];
    mysql_query("UPDATE `users` SET $sql
        `total_on_site` = '$totalonsite',
        `lastdate` = '$realtime'
        WHERE `id` = '$user_id'
    ");
} else {
    
    $sid = md5($ip . $agn);
    $movings = 0;
    $req = mysql_query("SELECT * FROM `cms_guests` WHERE `session_id` = '$sid' LIMIT 1");
    if (mysql_num_rows($req)) {  //This is the part prompted on error line 157--------
        
        $res = mysql_fetch_assoc($req);
        $movings = $res['movings'];
        if ($res['sestime'] < ($realtime - 300)) {
            $movings = 0;
            $sql .= "`sestime` = '$realtime',";
        }
        if ($res['ip'] != $ip)
            $sql .= "`ip` = '$ip',";
        if ($res['browser'] != $agn)
            $sql .= "`browser` = '" . mysql_real_escape_string($agn) . "',";
        if ($res['place'] != $headmod) {
            $movings = $movings + 1;
            $sql .= "`movings` = '$movings', `place` = '$headmod',";
        }
        mysql_query("UPDATE `cms_guests` SET $sql
        `lastdate` = '$realtime'
        WHERE `session_id` = '$sid'");
    } else {
        
        mysql_query("INSERT INTO `cms_guests` SET
            `session_id` = '$sid',
            `ip` = '$ip',
            `browser` = '" . mysql_real_escape_string($agn) . "',
            `lastdate` = '$realtime',
            `sestime` = '$realtime',
            `place` = '$headmod'
        ");
    }
}

/*
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a223123/public_html/incfiles/head.php on line 157

Thanks

Without showing all the code there is no way we can help.

Additionally you show the error is on line 157 and then provide only 61 lines of code so that there is no way for us to accurately see where your error is occurring.

Finally please wrap your code in

 tags - don't just dump and run.

head code see the text link of my head file…

hope you can correct whats wrongs

Get a forbidden on the link.

The error is because the associated query barfs and fails



    $req = mysql_query("SELECT * FROM `cms_guests` WHERE `session_id` = '$sid' LIMIT 1") or die(mysql_error());

see what that spits out.

what’s the right code for that sir, im noob on php and sql…

tell me how to crrect the code…?

thanks

Copy the code I gave you above and replace YOUR line 156

thank you sir…

i have 7 errors the same as that but in diffirent file… can you help me fix those errors sir? is it okay for you?

do i have to put the code, or die(mysql_error()); or other line error?

Use that after every QUERY so that if there is a mistake it will tell you what and why the query failed.

So every line that has mysql_query(“…”) or die(mysql_error());

thanks for your kind advice sir,

how how error like mysql_fetch_assoc(): supplied agument is not valid MySQL result resource…

can I put this code “or die(mysql_error())” also?

Thanks