O'Reilly logo

Programming ColdFusion MX, 2nd Edition by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating Existing Records

Updating a database record is a three-step process that involves a bit more work that just inserting a new record. The first step in the process is to identify the record to be updated; there are two ways to handle this task. Next, an HTML form containing the editable fields needs to be created. This form must be prepopulated with the data from the record to be edited. Finally, you need another template to take the updated form-field data and update the appropriate record in the database.

Choosing a Record to Update

Before you can make an update to a record, you need some sort of interface that allows you to choose the record you wish to modify. There are two general approaches to this interface. The first approach involves a URL-based technique for selecting the record to modify. The second approach utilizes a forms-based technique to achieve the same goal. Both approaches begin by querying a data source (in our case, the EmployeeDirectory table of the ProgrammingCF data source) to retrieve a list of all the records from the database. Usually, you need to retrieve only the primary key value and a distinguishing field or two. A primary key is necessary to ensure that you update only the record you intend to update. In many cases, the primary key is a single field that contains a unique value such as an auto-increment number or a UUID (Universally Unique Identifier—see CreateUUID( ) in Appendix B for more information). In some cases, the primary key may ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required