Invalid mysql result resource error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Curtis Mattoon
    New Member
    • Nov 2010
    • 7

    #1

    Invalid mysql result resource error

    Code:
    $email = sterile($_POST['email']);
    $zip = sterile($_POST['zip']);
    
    $sql = mysql_query("SELECT * FROM users WHERE email='$email'");
    if(is_bool($sql)){
    	die("BOOL");
    }
    while($row = mysql_fetch_assoc($sql)){
    // reset password, etc
    }
    Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in /public_html/reset-password.php on line 8


    I get this error from time to time, and still don't quite understand it. Typically, I spend around half an hour changing my query string until I have it back to how it was originally, then it magically starts working.

    From reading up on it, I've gathered that this error generally occurs when the query returns a boolean result, or no result at all. (Hence the is_bool test code).

    The curious part about this is.. despite the error, it still successfully queries the database, generates a random password, updates it in the database, and sends an email to the stored address.

    Any thoughts??

    Thanks!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    The curious part about this is.. despite the error, it still successfully queries the database, generates a random password, updates it in the database, and sends an email to the stored address.
    it looks like you’re using several mysql resources in one script. it may be that on some point you use the wrong resource (e.g. from INSERT/UPDATE) for mysql_fetch_ass oc().

    Comment

    Working...