User Guide

102 Chapter 7 Updating Your Database
Inserting Data
You usually use two application pages to insert data into a database:
An insert form
An insert action page
You can create an insert form with standard HTML form tags or with
cfform tags (see
Creating Forms with the cfform Tag on page 136). When the user submits the form,
form variables are passed to a ColdFusion action page that performs an insert
operation (and whatever else is called for) on the specified data source. The insert
action page can contain either a
cfinsert tag or a cfquery tag with a SQL INSERT
statement. The insert action page should also contain a message for the end user.
Creating an HTML insert form
The following procedure creates a form using standard HTML tags.
To create an insert form:
1 Create a new application page in ColdFusion Studio.
2 Edit the page so that it appears as follows:
<html>
<head>
<title>Insert Data Form</title>
</head>
<body>
<H2>Insert Data Form</H2>
<form action="insertaction.cfm" method="post">
Employee ID:
<input type="text" name="Emp_ID" size="4" maxlength="4"><br>
First Name:
<input type="Text" name="FirstName" size="35" maxlength="50"><br>
Last Name:
<input type="Text" name="LastName" size="35" maxlength="50"><br>
Department Number:
<input type="Text" name="Dept_ID" size="4" maxlength="4"><br>
Start Date:
<input type="Text" name="StartDate" size="16" maxlength="16"><br>
Salary:
<input type="Text" name="Salary" size="10" maxlength="10"><br>
Contractor:
<input type="checkbox" name="Contract" value="Yes" checked>Yes<br>
<br>
<input type="Reset" value="Clear Form">
<!-- Submit button -->
<input type="Submit" value="Submit">
</form>
</body>
</html>