Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update query help

    Hello:

    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.
    Attached Files Attached Files

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Correct

  • #5
    New Coder
    Join Date
    May 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see what's happening. Thanks for the help.


  •  

    Posting Permissions

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