34 users online (0 members and 34 guests)  


  Results 1 to 9 of 9

Related

  1. Simple Appearing But Baffling Error    Forum: ASP Forum
    Replies: 1
  2. Replies: 8
  3. Replies: 0
  4. 500 server error with VERY simple cgi??!!    Forum: CGI Perl Forum
    Replies: 3
  5. Error MySQL Error: 1064 - subqueries    Forum: PHP Forum
    Replies: 0
  1. #1
    deftonez4me's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2006
    Posts
    4

    Question Unexpected Error on Simple UPDATE Query

    Some one please help!! On one of the pages on the web site i am currently writing, I am getting a MySQL_fetch_array Error that is baffling me, over what should be a SIMPLE Update Query.!
    • I've seen the error 100's of times before: "mysql_fetch_array(): supplied argument is not a valid MySQL result resource"
    • When i usually get this, its always something small such as putting a single quote instead of a double . This time, i been looking at this same error for almost 6 hours
    Here's the Code Snippet:
    -------------------------------------------------------------------------
    $new_bid_count = $row['bids'] + 1;
    $new_current_bid = $_POST['place_bid'];

    //update post record
    $query5 = "UPDATE 'needed_posts' SET 'bids'='".$new_bid_count."', 'current_bid'='".$new_current_bid."' WHERE 'post_id'='".$_SESSION['post_id']."'";

    $result5 = @mysql_fetch_array($query5);
    //make sure the query executed successfully
    if(!$result5)
    {
    echo '<p><font color="red" size="+1">Update query unsuccessful!<br>';
    }
    else
    {
    echo '<p><font color="red" size="+1">Thank you for your bid!</font></p>';
    echo "Go back <a href='index.php'>Home</a>";
    include_once('footer.html');
    exit();
    }
    ---------------------------------------------------------------------------------
    Here's a screenshot of the entire error code:





    -------------------------------------------------------------------------------------
    Here's a screenshot taken before error takes place:


    -------------------------------------------------------------------------------------
    If anybody can help me i would be most grateful!! If you need anymore info about the page/site in order to help you figure this out just let me know.

    Thanks in advance!!!

  2. #2
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Unexpected Error on Simple UPDATE Query

    should be
    PHP Code:
    //update post record
    $query5 "UPDATE 'needed_posts' SET 'bids'='".$new_bid_count."', 'current_bid'='".$new_current_bid."' WHERE 'post_id'='".$_SESSION['post_id']."'";
    $result5 = @mysql_query($query5);
    $success5 = @mysql_fetch_array($result5);
    //make sure the query executed successfully
    if(!$success5)
    ... 
    In your original code, you have no result resource as you haven't performed a query to generate a result!

  3. #3
    deftonez4me's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2006
    Posts
    4

    Question Re: Unexpected Error on Simple UPDATE Query

    Alrite DeadMeat....

    Still got problems...think you can work your magic again and tell me what stupid detail am i looking over now?
    ----------------------------------------------------------------------
    Here's the error message:
    • An error occurred in script c:\easyphp1-8\www\config.inc on line 14: mysql_fetch_array(): supplied argument is not a valid MySQL result resourceAn error occurred in script c:\easyphp1-8\www\config.inc on line 14: mysql_fetch_array(): supplied argument is not a valid MySQL result resourceUpdate query unsuccessful!
    --------------------------------------------------------------------------------------
    ....and the code:

    //otherwise post type is auction bid
    else
    {
    $new_bid_count = $row['bids'] + 1;
    $new_current_bid = $_POST['place_bid'];

    //update post record
    $query5 = "UPDATE 'needed_posts' SET 'bids'='".$new_bid_count."', 'current_bid'='".$new_current_bid."' WHERE 'post_id'='".$_SESSION['post_id']."'";
    $result5 = @mysql_query($query5);
    $success5 = @mysql_fetch_array($result5);
    //make sure the query executed successfully
    if(!$success5)
    {
    echo '<p><font color="red" size="+1">Update query unsuccessful!</font></p><br>';
    }
    else
    {
    echo '<p><font color="red" size="+1">Thank you for your bid!</font></p>';
    echo "Go back <a href='index.php'>Home</a>";
    include_once('footer.html');
    exit();

    }

    //check to see if poster wants an email sent to him about the new bid
    if($row['receive_auto_emails'] > 0)
    {
    $auto_email_body = "A new bid has just been placed for your post: ".$row['title']."<br><br>";
    $auto_email_body .= "New Current Bid Amount: ".$_POST['place_bid']."<br>";
    $auto_email_body .= "Post Expiration date: ".$_SESSION['post_exp_date']."<br><br>";
    $auto_email_body .= "Thank you for using SetMyRates.com (c)2006 All rights reserved.";
    //mail($poster_email, 'A new bid has been received for your post!', $auto_email_body, 'From: webmaster@setmyrates.com');
    }


    }

    ---------------------------------------------------------------------------------
    Thanx again in advance!!!

  4. #4
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Unexpected Error on Simple UPDATE Query

    The error's on the same line (14) so I guess it's not successfully performing the query.
    I wonder if it's the single-quotes around the table-names and field-names - if you're going to quote them it needs to be a back-quote (`) not a single-quote (').
    A subtle difference, but one that can easily trip you!.

    Try changing the query to:
    PHP Code:
    $query5 "UPDATE `needed_posts` SET `bids`='".$new_bid_count."', `current_bid`='".$new_current_bid."' WHERE `post_id`='".$_SESSION['post_id']."'"
    or
    PHP Code:
    $query5 "UPDATE needed_posts SET bids='".$new_bid_count."', current_bid='".$new_current_bid."' WHERE post_id='".$_SESSION['post_id']."'"

  5. #5
    deftonez4me's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2006
    Posts
    4

    Re: Unexpected Error on Simple UPDATE Query

    That was one of the 1st things i tried...plugging the query into phpmyadmin, and cutting and pasting the PHP code they generated for me. Not only did that not work, but i've tried every combination of single/double/back quotes you could possibly imagine...and then some! I just don't get it....its not like it's even a complex query!

    OK...so back to stressing about it....if anyone has any ideas at all please let me know!

    One more thing...since your telling me your pretty sure it still has something to do with the query line...i figured i would try replacing the entire line of code with something really simple...a query i would be certain should work...so i replaced it with this:
    • $query5 = "UPDATE needed_posts SET bids='1' WHERE post_id='12' ";
    You'd think that would HAVE to work right.....NOPE....so i tried every single one of the following queries, all which gave me the exact same error:
    • $query5 = "UPDATE `needed_posts` SET `bids`='1' WHERE `post_id`='12' ";
    • $query5 = "UPDATE 'needed_posts' SET 'bids'='1' WHERE 'post_id'='12' ";
    • $query5 = "UPDATE `needed_posts` SET `bids`='1' WHERE post_id='12'";
    • $query5 = "UPDATE 'needed_posts' SET 'bids'='1' WHERE post_id='12'";
    • $query5 = "UPDATE needed_posts SET bids='1' WHERE 'post_id'='12'";
    • $query5 = "UPDATE needed_posts SET bids='1' WHERE `post_id`='12'";
    • $query5 = "UPDATE 'needed_posts' SET bids='1' WHERE 'post_id'='12'";
    • $query5 = "UPDATE `needed_posts` SET bids='1' WHERE `post_id`='12'";
    • $query5 = "UPDATE `needed_posts` SET bids='1' WHERE post_id='12'";
    • $query5 = "UPDATE 'needed_posts' SET bids='1' WHERE post_id='12'";
    • PLUS PROBABLY ANOTHER DOZEN DIFFERENT COMBOS....
    ANYONE?...ANYTHING?...WTF!?

  6. #6
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Unexpected Error on Simple UPDATE Query

    I'm kinda stuck - however the next step would be to check which line is at fault. We could be looking in completely the wrong place!
    Line 14 of the code you've posted is
    PHP Code:
    echo '<p><font color="red" size="+1">Update query unsuccessful!</font></p><br>'
    which clearly can't be generating that error.
    Also, the message states that the error is in config.inc - is the code you've posted from config.inc?
    If not, please post the code from config.inc (don't miss any lines) and wrap it in [ php ] tags so it's easier to read, please

  7. #7
    uthus's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Ft Hood
    Posts
    75

    Re: Unexpected Error on Simple UPDATE Query

    This may be a stupid question, but do 'bids' and 'post_id' actually exist in needed_posts? The reason I ask is because I've tried to do lookups on colums that I thought were there, but in all actuality weren't.

    U

  8. #8
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Unexpected Error on Simple UPDATE Query

    Also - do you need single qoutes around the numbers?

  9. #9
    uthus's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Ft Hood
    Posts
    75

    Re: Unexpected Error on Simple UPDATE Query

    I just looked at some of my scripts and I find that I don't use all the quotes like you do.

    Yours:
    PHP Code:
     $query5 "UPDATE 'needed_posts' SET 'bids'='".$new_bid_count."', 'current_bid'='".$new_current_bid."' WHERE 'post_id'='".$_SESSION['post_id']."'"
    Mine:
    PHP Code:
    $query5 "update needed_posts set bids='".$new_bid_count."', current_bid='".$new_current_bid."' where post_id='".$_SESSION['post_id']."'; 
    I find the fewer quotes I have to use, the less confusing it is.

    So inserting an known post_id would look like this:
    PHP Code:
    $query5 "UPDATE needed_posts SET bids=1 WHERE post_id=12"
    hth

    U



Tags for this Thread