The action page that you build to update data is very similar to the action page that you build to insert data. The update action page 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 UPDATE SQL statement, and SET and WHERE clauses to describe:
<CFQUERY NAME="QueryName" DATASOURCE="DataSourceName"> UPDATE Table SET ColumnName='UpdateValue', ColumnName='UpdateValue', ... WHERE PrimaryKey=UpdateValue </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.|
This code updates a particular employee in the Employees table:
<CFQUERY NAME="UpdateEmployee" DATASOURCE="HRApp"> UPDATE Employees SET FirstName='#Form.FirstName#', LastName='#Form.LastName#', Contract='#Form.Contract#' WHERE Employee_ID=#Form.Employee_ID# </CFQUERY>
|To build an update action page:|
UpdateForm.cfmand NO if it was not passed:
<CFIF IsDefined("Form.Contract") IS "Yes"> <CFSET ContractStatus="Yes"> <CFELSE> <CFSET ContractStatus="No"> </CFIF>
<CFQUERY NAME="UpdateEmployee" DATASOURCE="HRExpress"> </CFQUERY>
UPDATE Employees SET FirstName = '#Form.FirstName#',LastName = '#Form.LastName#', Department_ID = #Form.Department_ID#, StartDate = #Form.StartDate#, Salary = #Form.Salary#, Contract = '#ContractStatus#' WHERE Employee_ID = #Form.Employee_ID#
UpdateList.cfmin a browser.
UpdateAction.cfm updates the information in the database and redirects users to
EmpList.cfm so that they can confirm the changes.
Click here to see how the update list, form and action page should work.
Click here to see
You have completed the HR Manager Application. Move on to the chapter summary.