Blank Form Fields and Updating DB

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
v8killah
Forum Newbie
Posts: 3
Joined: Fri Dec 11, 2009 9:05 pm

Blank Form Fields and Updating DB

Post by v8killah »

Hi,

I have a form for updating records that correspond to a given ID. My SQL query is set to update all the fields corresponding to the ID based on values entered on the update form. However, if some of the fields are left blank, the record is updated with these blank fields. I only want to update the fields that have text in them because those are fields the user wishes to modify. How can I address this?

Thank you
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Blank Form Fields and Updating DB

Post by Christopher »

Loop through your list of fields and check if the $_POST value for the field is set. If it is, add a name='value' to the list of fields in the SET clause.
(#10850)
Post Reply