Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: php mysql error

  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts

    php mysql error

    I have a script that stores and removes sessions on my website, but for some reason i get this error sometimes, even though the script is run correctly.

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\domains\opjeplaats.nl\wwwroot\darkness\Webtemp\includes\sessions.php on line 84
    Here is where the problem is (arrows indicate the error) :

    PHP Code:
        $sql="SELECT * FROM rfd_sessions";
        
    $result=mysql_query($sql);
        
    $ip=$_SERVER['REMOTE_ADDR'];
        
    $count=mysql_num_rows($result);
        if(
    $count>0){
       --->
    while($rows=mysql_fetch_assoc($result)){ 
    And

    PHP Code:
        $sql="SELECT * FROM rfd_sessions WHERE user_ip='$ip'";
        
    $result=mysql_query($sql);
        
    $count=mysql_num_rows($result);
        if(
    $count 1){
      --->
    while($rows=mysql_fetch_assoc($result)){ 
    When i reload the page the error does not appear, how can i make the errors stop coming up?

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,079
    Thanks
    2
    Thanked 320 Times in 312 Posts
    Since you are checking that there is at lest one row in the result set, it is highly likely that your code inside the while(){} loop is overwriting the $result variable. You would need to post your code for the whole while loop to get help with what it might be doing.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Ok well the first while loop is :

    PHP Code:
    if($count>0){
        while(
    $rows=mysql_fetch_assoc($result)){
            if(
    time()-$rows['lastaction_time'] >= 300){
                
    // Remove visitors completely to relief space on DB
                
    if($rows['user_id'] == 0){
                
    $ip=$rows['user_ip'];
                
    $sql="DELETE FROM rfd_sessions WHERE user_ip='$ip'";
                
    $result=mysql_query($sql);                
                }elseif(
    $rows['user_id'] != && $rows['logged'] == 1){
                
    $id=$rows['user_id'];
                
    $time=$rows['lastaction_time'];
                
    $sql="UPDATE rfd_sessions SET lastvisit_time='$time', logged=0 WHERE user_id='$id'";
                
    $result=mysql_query($sql);
            }
            } 
    2nd :

    PHP Code:
        if($count 1){
            while(
    $rows=mysql_fetch_array($result)){
                if(
    $rows['logged'] == 1){
            
    $sql="DELETE FROM rfd_sessions WHERE user_ip='$ip' AND user_id=0";
            
    $result=mysql_query($sql);
            }
            } 

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,079
    Thanks
    2
    Thanked 320 Times in 312 Posts
    So, like was already guessed, don't you suppose reusing the $result variable inside of the while() loops for a different query would affect the outer while loops?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Killermud (05-10-2009)

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Oh yeah, thanks for pointing that out, not sure how i missed than


  •  

    Posting Permissions

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