System information
Exercise 2: Adding trips with SQL INSERT statements 133
To add data using a SQL INSERT statement and a cfquery tag:
1.
Open the tripeditaction.cfm file in the my_app directory.
2.
Locate the <cfif isOk EQ "Yes"> tag near the end of the file. After the <H1>Trip Added
</H1>
line, add the following code in the following table to insert the data from the Form
variables into the trips table:
3.
Save the file.
For Code
Windows users,
using MS Access
<!--- Insert the new trip record into the Compass
Travel database. --->
<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>
UNIX users, using
PointBase
<!--- Insert the new trip record into the
Compass Travel database. --->
<!--- Use local variables to convert dates to JDBC format
(yyyy-mm-dd) from input format (mm/dd/yyyy). --->
<cfset JDBCdepartureDate = #Right(Form.departureDate,4)#
& "-" & #Left(Form.departureDate,2)# & "-"
& #Mid(Form.departureDate,4,2)#>
<cfset JDBCreturnDate = #Right(Form.returnDate,4)# & "-"
& #Left(Form.returnDate,2)# & "-"
& #Mid(Form.returnDate,4,2)#>
<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#', Date'#JDBCdepartureDate#',
Date'#JDBCreturnDate#',
#Form.price#,'#Form.tripLeader#', '#Form.photo#',
#Form.baseCost#, #Form.numberPeople#, '#Form.depositRequired#')
</cfquery>