Chapter 6: Updating Your Data
61
</HTML>
3.
Save the file as
insertform.cfm
in the
myapps
directory.
4.
View
insertform.cfm
in a browser.
Data Entry Form Notes and Considerations
Creating data entry fields for an HTML form is very simple:
•
You need only create the HTML form fields for each database field into which
you want to insert data.
•
The names of your form fields must be identical to the names of your database
fields.
•
You can use the full range of HTML input controls, including list boxes, radio
buttons, checkboxes, and multi-line text boxes in your forms.
•
ColdFusion uses the NAME attribute to map HTML form fields to the
corresponding database fields and inserts the data entered by the user into the
appropriate database fields.
Creating an Action Page to Insert Data
There are two ways to create an action page to insert data into a database.
The CFINSERT tag is the easiest way to handle simple inserts from either a CFFORM or
an HTML form.
For more complex inserts from a form submittal you can use a SQL INSERT statement
in a CFQUERY tag instead of a CFINSERT tag. The SQL INSERT statement is more
flexible because you can insert information selectively or use functions within the
statement.
To create an insert action page with CFINSERT:
1.
Create a new application page in Studio.
2.
Enter the following code:
4
<CFINSERT DATASOURCE="CompanyInfo" TABLENAME="Employees">
<HTML>
<HEAD>
<TITLE>Input Form</TITLE>
</HEAD>
<BODY>
<H1>Employee Added</H1>
<CFOUTPUT>
You have added #Form.FirstName# #Form.LastName# to the Employees
database.
</CFOUTPUT>
</BODY>
</HTML>
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...