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.
For
Windows users,
using MS Access
UNIX users, using
PointBase
Save the page and test it by opening the tripedit.cfm page in your browser.
3
120
Chapter 10: Lesson 6: Adding and Updating SQL Data
Code
<!--- 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>
<!--- 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>
Need help?
Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?
Questions and answers