The action page that you build to insert data needs to include:
You'll use the CFLOCATION tag to redirect users after the query insertion.
The CFQUERY tag supports a number of SQL statements that you use to insert, update, and delete records in a table.
For example, you'll use the INSERT statement to insert data into a database.
<CFQUERY NAME="QueryName" DataSource="DataSourceName"> INSERT INTO Table (ColumnName, ColumnName,..) VALUES ('ValueToInsert','ValueToInsert',..) </CFQUERY>
This code inserts an employee's last name and first name into the Employees table:
<CFQUERY NAME="AddEmployees" DATASOURCE="HRApp"> INSERT INTO Employees (FirstName, LastName) VALUES ('#Form.FirstName#','#Form.LastName#') </CFQUERY>
![]() |
Note: | The purpose of this guide is to get you up and running with ColdFusion Express. Allaire suggests that you purchase a book on SQL to learn how to use it efficiently. |
![]() |
To build an insert action page: |
InsertAction.cfm
in HomeSite.<CFIF IsDefined("Form.Contract") IS "Yes"> <CFSET ContractStatus="Yes"> <CFELSE> <CFSET ContractStatus="No"> </CFIF>
This ensures that a contract value always passes to the database.
<CFQUERY NAME="InsertEmployee" DATASOURCE="HRExpress">
INSERT INTO Employees (FirstName, LastName, Department_ID, StartDate, Salary, Contract) VALUES ('#Form.FirstName#','#Form.LastName#', #Form.Department_ID#,#Form.StartDate#, #Form.Salary#, '#ContractStatus#')
</CFQUERY>
EmpList.cfm
.<CFLOCATION URL="EmpList.cfm">
InsertAction.cfm
by adding employees to the database.Click here to see how the form and action page should work.
Click here to see InsertAction.cfm
's code.
Move on in this chapter to learn about updating data.
![]() |
Note: | Almost all links will work at this time. |