Share this Page URL
Help

Part 1: Week 1 At a Glance > Changing the Contents of a Database with ColdFusio... - Pg. 100

100 Chapter 7. Changing the Contents of a Database with ColdFusion In Day 6, "Creating Your First Web Application," you built your first ColdFusion templates to create a two-page drill-down application. Your templates used basic queries to draw information from a client's database and present the data to users as an HTML page. In today's lesson we'll look at the other side of ColdFusion--input. You'll learn how standard Web forms can be used to get information into a ColdFusion database. We'll also cover · The <CFINSERT> and <CFUPDATE> tags · An introduction to Web forms · Creating forms to insert or update data · Troubleshooting insert and update operations Defining a Sample Application After successfully completing your first Web application for Gargantuan Electronics as described in Day 6, you return from your Mexican vacation to find your answering machine full of messages from the Gargantuan rep. She loves the application you created, but it has now become so popular with the Gargantuan's tech department that all the employees want the ability to personally log their strange calls, rather than leaving it to the "database guy." When you phone her back, the rep tells you the problem is that not all the tech-support employees are familiar with using database software. She wants you to build a Web interface that will enable any techperson to input the details of a call, right from his Web browser. However, having seen other paperwork submitted by tech-support personnel, she knows that certain members of the department can't spell or punctuate their way out of a wet grocery sack. For this reason she also requests that you create a special administrator page that will enable her to edit the text in existing entries. After she hangs up, you remove your sombrero and huraches, hang your new velveteen Elvis tap- estry near your desk, and set to work. Introducing <CFINSERT> and <CFUPDATE> You'll need to understand two new ColdFusion tags to create the new pages, <CFINSERT> and <CFUPDATE>. Both are used when you want to change the information in a database. Both work like SQL queries in reverse--instead of selecting information from a database table, these tags change or add values to the fields you specify. Use <CFINSERT> when you need to add a new record to an existing table. It doesn't require any qualifying statements to do its work. It simply takes the variables you've defined, matches them with field names in your table, and inputs the lot as a new record.