View Full Version : Update query help

06-07-2007, 07:15 PM

I have a table which contains 30 fields. I have a form which uses 15 of the 30 fields. And, the form has additional fields that are updating a another table.

I created the form and brought in the data I needed from the table. The data is coming from the tables into the form correctly.

I proceed to make my changes and I click Submit. At first, when I wrote my update statement I had SET all 30 fields whether they appeared on the form or not. When I clicked Submit at this point, I kept getting an undefined index message on all fields that are in the table but are not in the form.

I then proceeded to modify my update statement by eliminating the fields that do not show up on my form. Doing this apparently got rid of the undefined index messages. So, I click Submit again and this time, the fields that needed to be changed were changed, the fields that are in the table but not in the form are now empty, and the second table was not updated.

First, how do I write an update statement which will allow me to update certain fields even if those fields do not appear on a form and not erase the information that is stored in those fields?

Can someone help me out? There are three scripts which are used for the whole process. I attached the scripts as files because I didn't want to have people do lots of scrolling.

The first script, face_sheet_update.php, selects the client record we want to update.
The second script, face_sheet_update_pg1.php, queries and selects all the fields and tables which are used in the form. This script also displays the form with the data and then posts to the third script.
The third script, face_sheet_update_process.php, contains the update statements for the tables which are being used with this specific form. The last update query in this script is not updating the fields. Currently, this table is starting off with empty fields. I think I have to do an insert of the data not an update. I'm not sure.

Any help will be greatly appreciated. Thank you in advance.

06-07-2007, 07:50 PM
I haven't looked at the files because I'm a little short on time atm.
However, if you are updating values and it is resetting something it shouldn't be, then it sounds like you have an update anomoly. Running an update query does not require all fields to be filled in and will only update the values that have been provided for a given primary key(generally) or whatever search criteria.
Without seeing a schema I cannot be certain, but you may need to look at performing 'database normalization'. Search that on google, see if that solves the problems.

06-07-2007, 09:57 PM
So, for an update query, I should only be setting the fields for update that are in the form. If I'm not using any of the other fields in the table, they should not be included in the update query.

Is that right?

06-07-2007, 10:52 PM

06-08-2007, 02:13 AM
I see what's happening. Thanks for the help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum