[RESOLVED] mysql update query fails - Page 2
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: [RESOLVED] mysql update query fails

  1. #16
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Quote Originally Posted by David P View Post
    PHP 5 will not reenter the same information.
    PHP (any version) doesn't enter any information on its own... it does exactly what you tell it to do.

    Quote Originally Posted by David P View Post
    Checking a single entry like say (cat) is easy, but checking to see if the contents of a POSTed textarea is identical to what is in the mysql field is not.
    Who said you had to check what was in the database? You already know what was in the database when you first generated that form, so you could either a) store that data in a session, or b) store that data in hidden form elements or in cookies. If you get a submission where the POST'ed data matches the data you previously used to generate the update page, then you know that the user didn't change anything - thus, there's no reason to even bother connecting to your DB, let alone trying to query it in any way.

    But again, you could accomplish this quite easily on the client side of things using Javascript, meaning you could save even more resources by not allowing the form to be submitted in the first place.

    Quote Originally Posted by David P View Post
    PHP Code:
    if ($r === $_SESSION['duty']) { // also tried ($r == $_SESSION['duty']) 
    Neither one of those comparisons makes any sense; mysqli_query() is going to (hopefully) return a resource, yet you're trying to compare it to a string (POST'ed data).

    Quote Originally Posted by David P View Post
    If the purpose of PHP 5 not re-entering in the same data in an update is to save time and resources, but you have to perform an additional query to test the MySQL data against the posted variable data, then what have you gained?
    Not much (i.e. probably nothing), which is why I never suggested doing that.

  2. #17
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Just to clarify, MySQL_num_rows() returning 0 when no rows were actually updated is

    a) not a new behavior - it has always done so

    b) not a behavior of PHP - it's the value that MySQL returns.

  3. #18
    Member
    Join Date
    Aug 2006
    Location
    Montgomery, AL
    Posts
    64
    I just changed and tested my script and I have it working. I was pulling the information out of the database to compare it to the posted variable instead of testing for identical content in the query.
    PHP Code:
    $q "SELECT * FROM duties WHERE duty_id='$duty_id' AND duty='".$_SESSION['duty']."'"
    This works and satisfies my immediate need, but as some suggested, checking for any change of content prior to the query also makes sense so I'll experiment with that some.

    I don't seem to recall earlier versions of PHP or MySQL throwing errors when attempting to update the database with the same information. Maybe it did and I didn't notice, although it it wasn't working I'm sure someone would have notified me. Hmmm. This is why I thought that this was new behavior.

    I just got my book in on PHP 5 and MySQL 5 and have began updating my pages with the mysqli. I'll use the procedural method since it's closer to what I'm used to. I've also started reading about JavaScript and I can see where it could certainly be very beneficial at times.

    Anyway, thanks for all the help on this. I know that teaching can be very frustrating at times, but I appreciate your willingness to do it. I'm not immediately sure as to how to mark this topic resolved but I'll look into that more after I make this post.

  4. #19
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Quote Originally Posted by David P View Post
    I don't seem to recall earlier versions of PHP or MySQL throwing errors when attempting to update the database with the same information.
    That behavior has certainly been around for several versions (and, subsequently, several years). From the MySQL 4.1 manual for the UPDATE query:

    Quote Originally Posted by MySQL 4.1 Manual
    If you set a column to the value it currently has, MySQL notices this and does not update it.
    (It follows that if you do that for all columns in a given row, none of the columns in that row are updated, thus there are 0 affected rows.)

  5. #20
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,910
    Quote Originally Posted by DavidP
    I don't seem to recall earlier versions of PHP or MySQL throwing errors when attempting to update the database with the same information. Maybe it did and I didn't notice, although it it wasn't working I'm sure someone would have notified me. Hmmm. This is why I thought that this was new behavior.
    And it's not throwing errors now. Your code is saying that there is an error.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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