SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run an update from form, all fields or just changed?

    Not sure if this would be more appropriate in the database section, but I feel this is more a PHP question.

    When you have a form that gets populated with results from a database, then the user has the ability to make changes to the forms information (such as for an Employee record where they update an address). Is it preferred to issue a full UPDATE command with ALL the fields, or iterate through each field, test if it has been modified (whether it is a text field, checkbox, etc) and then compile the SQL Update query to ONLY update the changed fields?

    On the one hand I feel that it would be quite a bit more overhead to check every field to see if it matches the original values, but then it also seems a bit of overkill to rewrite every field in a database record when possibly only a single item needs to be changed.

    What is the preferred/recommended practice in a case such as this?

    Greg
    Greg Hicks
    Tekamba Computers, LLC
    greg@tekamba.com
    http://tekamba.com

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If your form had 20 fields and you think most users would only ever change one or two fields at most, then I'd be tempted to use Ajax methodologies to update those fields one at a time -- return positive feedback to users via the GUI (though you have to be consistent how you handle updates from then on in).

    If you do not want to/cannot rely on JS, then I would just replace all the form fields by default.

    Not doing so suggests you are storing the form data somewhere such as session data.

    That all sounds overcomplicated.

    If some of the fields are multi-thousand character text fields, then I'd move those to their own forms.


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
  •