System information

136 Chapter 12: Lesson 9: Enabling Database Maintenance
To add data using cfinsert:
1.
Open the tripeditaction.cfm file from the my_app directory in your editor.
2.
Remove the entire AddTrip cfquery code block that you added in Exercise 2: Adding trips with
SQL INSERT statements:
<cfquery name="AddTrip" datasource="compasstravel">
INSERT INTO Trips (tripName, eventType, tripDescription,
tripLocation,departureDate, returnDate, price, tripLeader,
photo, baseCost, numberPeople, depositRequired)
VALUES ('#Form.tripName#', #Form.eventType#,
'#Form.tripDescription#',
'#Form.tripLocation#','#Form.departureDate#',
'#Form.returnDate#',
#Form.price#, '#Form.tripLeader#', '#Form.photo#',
#Form.baseCost#, #Form.numberPeople#, '#Form.depositRequired#')
</cfquery>
3.
Add the following cfinsert tag to insert data into the trips table in the same location as the
code that you just deleted:
<cfinsert datasource="CompassTravel" tablename="trips">
4.
Save the file.
To test the modified code:
1.
Open the tripedit.cfm page in your browser.
2.
In the tripedit.cfm page, enter in the fields the values in the following table, and then click Save:
After the new trip is written to the database, the following message appears: You have added
NH White Mountains to the trips database.
Field Value
Trip Name NH White Mountains
Event Type Mountain Climbing
Trip Description Climb the 5 highest peaks in the New Hampshire White Mountains.
Trip Location Northeastern New Hampshire
Departs 05/01/2005
Returns 05/10/2005
Number of People 15
Price 1200
Base Cost 600
Deposit Required Yes
Trip Leader Tom Finn
Photo File Name whitemountains.jpg