Programming instructions
132 Lesson 6 Adding and Updating SQL Data
Tip: To save time, you can copy this code from the tripsinsertquery.txt file (for Windows
users) or from tripinsertqueryunix.txt (for UNIX users) in the solutions directory.
3 Save the page and test it by opening the tripedit.cfm in your browser.
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>