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: |
<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>
insertpage.cfm.
insertform.cfm in a browser, enter values, and click the Submit button.
| To create an insert page with CFQUERY: |
<CFQUERY NAME="AddEmployee"
DATASOURCE="CompanyInfoB">
INSERT INTO Employees (Fi', '#Form.LastName#',
'#Form.Phone#')
</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>
insertpage.cfm.
isertform.cfm in a browser, enter values, and click the Submit button.