Using Forms to Update Records

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps
By Barry Moore
Table of Contents
Step 6.  Updating, Inserting, and Deleting Database Records


Business information changes, product prices go up, staff details change, and we need to be able to update this information quickly and easily. The first area of database manipulation we are going to look at is updating information that already exists in a database.

Dynamically Populating Forms

As we have seen previously, forms are a quick and easily understood way for users to interact with our web site. To update information in the database, we are going to use the same form page/action page combination we used before, except with a little twist. First, instead of giving users a blank form to fill out, we will present them with a form containing the current data for the record they want to edit. Second, instead of pulling information out of the database with the action page, we will be pushing information into the database.

The first part, creating our form, is relatively simple. On our form page, we simply start with a query to pull information for a particular record. We will use a URL variable to determine exactly which record to pull.

Then we will create a form whose structure is exactly the same as our database record's structure, and we'll use the VALUE attribute of our <INPUT> or <CFINPUT> tag to populate the form field with the corresponding information from our database query. For convenience and readability, we will make sure the NAME attribute for each form element is the same as the database field we want to update. We will worry about the action page in just a moment. Let's first take a look at a form example.


    Team-Fly    
    Top
     



    ColdFusion MX. From Static to Dynamic in 10 Steps
    ColdFusion MX: From Static to Dynamic in 10 Steps
    ISBN: 0735712964
    EAN: 2147483647
    Year: 2002
    Pages: 140
    Authors: Barry Moore

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net