SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    819
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question 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:

    102) $totalRows_getHHH = mysql_num_rows($all_getHHH);

    129) $totalRows_getEvents = mysql_num_rows($all_getEvents);

    150) $totalRows_getNews = mysql_num_rows($all_getNews);

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

    The complete request:
    Code:
    $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?

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,995
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    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?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    819
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    819
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!

  6. #6
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  8. #8
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $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
    Last edited by spikeZ; Mar 23, 2011 at 08:33. Reason: code tags added

  9. #9
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 [php] tags - don't just dump and run.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  10. #10
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    head code see the text link of my head file..

    hope you can correct whats wrongs

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Get a forbidden on the link.

    The error is because the associated query barfs and fails
    PHP Code:

        $req 
    mysql_query("SELECT * FROM `cms_guests` WHERE `session_id` = '$sid' LIMIT 1") or die(mysql_error()); 
    see what that spits out.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what's the right code for that sir,, im noob on php and sql...

    tell me how to crrect the code...?

    thanks

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Copy the code I gave you above and replace YOUR line 156
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  15. #15
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do i have to put the code, or die(mysql_error()); or other line error?

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by tokgad View Post
    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());
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •