Programming instructions

126 Lesson 5 Implementing the Browsing and Maintenance Database Functions
DELETE FROM trips WHERE tripID = #Form.RecordID#
Exercise: handle search and delete in maintenance action page
In this exercise, you will link the search function developed in Lesson 4 to the main page.
Further, you will provide code to support the trip delete function. Then you will test this
functionality by deleting a trip, then searching for it to ensure it was deleted successfully.
Follow these steps to create the maintenance action page that implements the search and
delete functionality.
To create the maintenance action page:
1 In your editor, create a CFM page.
2 Delete any default lines of code if your editor automatically adds them.
3 To handle the Search and Delete buttons from the Trip Detail page, enter the
following code:
<!--- SEARCH BUTTON--->
<cfif IsDefined("Form.btnSearch")>
<cflocation url="tripsearch.cfm">
<!--- DELETE BUTTON --->
<cfelseif IsDefined("Form.btnDelete")>
<cfquery name="DeleteRecord" dataSource="CompassTravel">
DELETE FROM trips WHERE tripID = #Form.RecordID#
</cfquery>
<cflocation url="tripdetail.cfm">
</cfif>
4 Save the page as maintenanceaction.cfm in the my_app directory.
5 View the tripdetail.cfm page in a browser.
The current trip is Nepal. Notice that the destination for Nepal Summit Challenge
trip is Imji Himal, Nepal.
6 Click Search.
The Trip Search page appears.