User Guide

62 Developing Web Applications with ColdFusion
3. Save the page. as insertpage.cfm.
4. View
insertform.cfm in a browser, enter values, and click the Submit button.
5. The data is inserted into the Employees table and the message appears.
To create an insert page with CFQUERY:
1. Create a new application page in Studio.
2. Enter the following code:
4 <CFQUERY NAME="AddEmployee"
4 DATASOURCE="CompanyInfoB">
4 INSERT INTO Employees (Fi’, ’#Form.LastName#’,
4 ’#Form.Phone#’)
4 </CFQUERY>
<HTML>
<HEADER>
<TITLE>Insert Action Page</TITLE>
</HEADER>
<BODY>
<H1>Employee Added</H1>
<CFOUTPUT>
You have added #Form.FirstName# #Form.LastName# to the Employees
database.
</CFOUTPUT>
</BODY>
</HTML>
3. Save the page. as insertpage.cfm.
4. View
isertform.cfm in a browser, enter values, and click the Submit button.
5. The data is inserted into the Employees table and the message appears.
Updating Data
Updating data in a database is usually done with two pages:
An update form
An update action page
You can create an update form with CFFORM tags or HTML form tags. The update
form calls an update action page, which can contain either a CFUPDATE tag or a
CFQUERY tag with a SQL UPDATE statement. The update action page should also
contain a message for the end user that reports on the update completion.