home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2002-04-08 | 38.7 KB | 1,074 lines
ml> <head> <title>Compass Travel Trip Maintenance</title> </head> <body> <cfform action="tripeditaction.cfm" method="post"> <!--- Field: Trip Maintenance Image ---> <img src="images/tripmaintenance.gif"> <p> <table> <!--- Field: tripName ---> <tr> <td valign="top"> Trip Name </td> <td> <cfinput maxlength="50" size="50" required="Yes" name="tripName" message="Trip name must not be blank."> </td> </tr> <!--- Field: eventType ---> <tr> <td valign="top"> Type of Event </td> <td> <cfselect size="1" name="eventType" required="Yes" message="Type of event must be selected."> <option value="1" selected>Surfing</option> <option value="2">Mountain Climbing</option> <option value="3">Mountain Biking</option> </cfselect> </td> </tr> <!--- Field: tripDescription ---> <tr> <td valign="top"> Trip Description </td> <td> <textarea cols="50" rows="5" name="tripDescription"></textarea> </td> </tr> <!--- Field: tripLocation ---> <tr> <td valign="top"> Trip Location </td> <td> <cfinput name="tripLocation" required="Yes" message="Trip location must not be blank." size="50"> </td> </tr> <!--- Field: departureDate ---> <tr> <td valign="top"> Departure Date </td> <td> <cfinput name="departureDate" required="Yes" size="10" validate="date" message="Departure date must be a valid date."> </td> </tr> <!--- Field: returnDate ---> <tr> <td valign="top"> Return Date </td> <td> <cfinput size="10" name="returnDate" required="Yes" validate="date" message="Return date must be a valid date."> </td> </tr> <!--- Field: numberPeople ---> <tr> <td valign="top"> Number of People </td> <td> <cfinput size="6" name="numberPeople" required="Yes" validate="integer" message="The number of people field must be a number and cannot be blank."> </td> </tr> <!--- Field: Price ---> <tr> <td valign="top"> Price </td> <td> <cfinput size="10" name="price" required="Yes" validate="integer" message="Price is required and must be numeric."> </td> </tr> <!--- Field: baseCost ---> <tr> <td valign="top"> Base Cost </td> <td> <cfinput size="10" name="baseCost" required="Yes" validate="integer" message="Base cost is required and must be numeric."> </td> </tr> <!--- Field: depositRequired ---> <tr> <td valign="top"> Deposit Required </td> <td> <cfinput type="checkbox" value="Yes" name="depositRequired"> </td> </tr> <!--- Field: tripLeader ---> <tr> <td valign="top"> Trip Leader </td> <td> <cfinput maxlength="50" size="50" name="tripLeader" required="Yes" message="A trip leader must be specified."> </td> </tr> <!--- Field: photo ---> <tr> <td valign="top"> Photo File Name </td> <td> <cfinput maxlength="50" size="50" name="photo" required="Yes" message="Valid photo file name must be specified."> </td> </tr> </table> <p> <input type="submit" value="Save"> <input type="submit" value="Cancel" name="btnCancel"> </cfform> </body> </html> <!--- Macromedia ColdFusion(r) 6.0 - Getting Started Code Examples ---> <!-- CF Forms Validation --> <script language="JavaScript"> function isitFutureDate(oForm, oTag, dateString) { /* function isitFutureDate parameters: oForm, oTag, dateString returns: boolean oForm is the CFForm object. All ONVALIDATE calls pass this argument. This function ignores it. oTag is the CFForm current tag object. All ONVALIDATE calls pass this argument. This function ignores it. dateString is the value of the current tag object. It should be a date passed as a string in the following format: MM/DD/YYYY. This means that months and days require leading zeros!! Returns true if the date passed is greater than today's date Returns false if the date passed is NOT greater than todays date. */ // Check to make sure the date is zero filled with 4 digit year and therefore 10 characters long. if (dateString.length != 10) return false; var now = new Date(); var today = new Date(now.getYear(),now.getMonth(),now.getDate()); var testdate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5)); if (testdate > now) return true; else return false; } function validateTripDateRange(oForm, oTag, dateString) { /* parameters: oForm, oTag, dateString returns: boolean oForm is the CFForm object. All ONVALIDATE calls pass this argument. This function ignores it. oTag is the CFForm current tag object. All ONVALIDATE calls pass this argument. This function ignores it. dateString is the value of the current tag object. It should be a date passed as a string in the following format: MM/DD/YYYY. This means that months and days require leading zeros!! Returns true if the date passed is a future date greater than the departure date Returns false if the date passed is NOT a future date greater than departure date. */ //Edit to make sure that Return date is Later than departure date. var returnDateString; //First check to see if the Return Date is a valid future date if (isitFutureDate(oForm, oTag, dateString) == false) return false; var departureDate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5)); returnDateString = document.forms(0).item("returnDate").value; var returnDate = new Date(returnDateString.substring(6,10), returnDateString.substring(0,2)-1, returnDateString.substring(3,5)); if (departureDate > returnDate) return false; else return true; } </SCRIPT> <cfquery name="GetEvents" datasource="CompassTravel"> SELECT eventType, eventTypeID FROM eventtypes </cfquery> <html> <head> <title>Compass Travel Trip Maintenance</title> </head> <body> <cfform action="tripeditaction.cfm" method="post"> <!--- Field: Trip Maintenance Image ---> <img src="images/tripmaintenance.gif"> <p> <table> <!--- Field: tripName ---> <tr> <td valign="top"> Trip Name </td> <td> <cfinput maxlength="50" size="50" required="Yes" name="tripName" message="Trip name must not be blank."> </td> </tr> <!--- Field: eventType ---> <tr> <td valign="top"> Type of Event </td> <td> <cfselect size="1" name="eventType" required="Yes" message="Type of event must be selected."> <cfoutput query="GetEvents"> <option value="#GetEvents.eventTypeID#">#GetEvents.eventType#</option> </cfoutput> </cfselect> </td> </tr> <!--- Field: tripDescription ---> <tr> <td valign="top"> Trip Description </td> <td> <textarea cols="50" rows="5" name="tripDescription"></textarea> </td> </tr> <!--- Field: tripLocation ---> <tr> <td valign="top"> Trip Location </td> <td> <cfinput name="tripLocation" required="Yes" message="Trip location must not be blank." size="50"> </td> </tr> <!--- Field: departureDate ---> <tr> <td valign="top"> Departure Date </td> <td> <cfinput name="departureDate" size="10" validate="date" onvalidate="isitFutureDate" message="Departure date must be a valid future date (mm/dd/yyyy)."> </td> </tr> <!--- Field: returnDate ---> <tr> <td valign="top"> Return Date </td> <td> <cfinput size="10" name="returnDate" validate="date" onvalidate="validateTripDateRange" message="Return date must be a valid date greater than departure date (mm/dd/yyyy)."> </td> </tr> <!--- Field: numberPeople ---> <tr> <td valign="top"> Number of People </td> <td> <cfinput size="6" name="numberPeople" required="Yes" validate="integer" message="The number of people field must be a number and cannot be blank."> </td> </tr> <!--- Field: Price ---> <tr> <td valign="top"> Price </td> <td> <cfinput size="10" name="price" required="Yes" validate="integer" message="Price is required and must be numeric."> </td> </tr> <!--- Field: baseCost ---> <tr> <td valign="top"> Base Cost </td> <td> <cfinput size="10" name="baseCost" required="Yes" validate="integer" message="Base cost is required and must be numeric."> </td> </tr> <!--- Field: depositRequired ---> <tr> <td valign="top"> Deposit Required </td> <td> <cfinput type="checkbox" value="Yes" name="depositRequired"> </td> </tr> <!--- Field: tripLeader ---> <tr> <td valign="top"> Trip Leader </td> <td> <cfinput maxlength="50" size="50" name="tripLeader" required="Yes" message="A trip leader must be specified."> </td> </tr> <!--- Field: photo ---> <tr> <td valign="top"> Photo File Name </td> <td> <cfinput maxlength="50" size="50" name="photo" required="Yes" message="Valid photo file name must be specified."> </td> </tr> </table> <p> <input type="submit" value="Save"> <input type="submit" value="Cancel" name="btnCancel"> </cfform> </body> </html> <!--- Macromedia ColdFusion(r) 6.0 - Getting Started Code Examples ---> <!-- CF Forms Validation --> <script language="JavaScript"> function isitFutureDate(oForm, oTag, dateString) { /* function isitFutureDate parameters: oForm, oTag, dateString returns: boolean oForm is the CFForm object. All ONVALIDATE calls pass this argument. This function ignores it. oTag is the CFForm current tag object. All ONVALIDATE calls pass this argument. This function ignores it. dateString is the value of the current tag object. It should be a date passed as a string in the following format: MM/DD/YYYY. This means that months and days require leading zeros!! Returns true if the date passed is greater than today's date Returns false if the date passed is NOT greater than todays date. */ // Check to make sure the date is zero filled with 4 digit year and therefore 10 characters long. if (dateString.length != 10) return false; var now = new Date(); var today = new Date(now.getYear(),now.getMonth(),now.getDate()); var testdate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5)); if (testdate > now) return true; else return false; } function validateTripDateRange(oForm, oTag, dateString) { /* parameters: oForm, oTag, dateString returns: boolean oForm is the CFForm object. All ONVALIDATE calls pass this argument. This function ignores it. oTag is the CFForm current tag object. All ONVALIDATE calls pass this argument. This function ignores it. dateString is the value of the current tag object. It should be a date passed as a string in the following format: MM/DD/YYYY. This means that months and days require leading zeros!! Returns true if the date passed is a future date greater than the departure date Returns false if the date passed is NOT a future date greater than departure date. */ //Edit to make sure that Return date is Later than departure date. var returnDateString; //First check to see if the Return Date is a valid future date if (isitFutureDate(oForm, oTag, dateString) == false) return false; var departureDate = new Date(dateString.substring(6,10), dateString.substring(0,2)-1, dateString.substring(3,5)); returnDateString = document.forms(0).item("returnDate").value; var returnDate = new Date(returnDateString.substring(6,10), returnDateString.substring(0,2)-1, returnDateString.substring(3,5)); if (departureDate > returnDate) return false; else return true; } </SCRIPT> <cfquery name="GetEvents" datasource="CompassTravel"> SELECT eventType, eventTypeID FROM eventtypes </cfquery> <html> <head> <title>Compass Travel Trip Maintenance</title> </head> <body> <cfform action="tripeditaction.cfm" method="post"> <!--- Field: Trip Maintenance Image ---> <img src="images/tripmaintenance.gif"> <p> <table> <!--- Field: tripName ---> <tr> <td valign="top"> Trip Name </td> <td> <cfinput maxlength="50" size="50" required="Yes" value=#tripName# name="tripName" message="Trip name must not be blank."> </td> </tr> <!--- Field: eventType ---> <tr> <td valign="top"> Type of Event </td> <td> <cfselect size="1" name="eventType" required="Yes" message="Type of event must be selected."> <cfoutput query="GetEvents"> <cfif GetEvents.eventTypeID EQ #eventTypeIdentifier#> <option selected value="#GetEvents.eventTypeID#"> <cfelse> <option value="#GetEvents.eventTypeID#"> </cfif> #GetEvents.eventType#</option> </cfoutput> </cfselect> </td> </tr> <!--- Field: tripDescription ---> <tr> <td valign="top"> Trip Description </td> <td> <cfinput size="50" maxlength=250 required="Yes" name="tripDescription" value=#tripDescription#> </td> </tr> <!--- Field: tripLocation ---> <tr> <td valign="top"> Trip Location </td> <td> <cfinput name="tripLocation" value=#tripLocation# required="Yes" message="Trip location must not be blank." size="50"> </td> </tr> <!--- Field: departureDate ---> <tr> <td valign="top"> Departure Date </td> <td> <cfinput name="departureDate" size="10" value=#departureDate# validate="date" onvalidate="isitFutureDate" message="Departure date must be a valid future date (mm/dd/yyyy)."> </td> </tr> <!--- Field: returnDate ---> <tr> <td valign="top"> Return Date </td> <td> <cfinput size="10" name="returnDate" value=#returnDate# validate="date" onvalidate="validateTripDateRange" message="Return date must be a valid date greater than departure date (mm/dd/yyyy)."> </td> </tr> <!--- Field: numberPeople ---> <tr> <td valign="top"> Number of People </td> <td> <cfinput size="6" name="numberPeople" value=#numberPeople# required="Yes" validate="integer" message="The number of people field must be a number and cannot be blank."> </td> </tr> <!--- Field: Price ---> <tr> <td valign="top"> Price </td> <td> <cfinput size="10" name="price" value=#price# required="Yes" validate="integer" message="Price is required and must be numeric."> </td> </tr> <!--- Field: baseCost ---> <tr> <td valign="top"> Base Cost </td> <td> <cfinput size="10" name="baseCost" value=#baseCost# required="Yes" validate="integer" message="Base cost is required and must be numeric."> </td> </tr> <!--- Field: depositRequired ---> <tr> <td valign="top"> Deposit Required </td> <td> <cfinput type="checkbox" value=#depositRequired# name="depositRequired"> </td> </tr> <!--- Field: tripLeader ---> <tr> <td valign="top"> Trip Leader </td> <td> <cfinput maxlength="50" size="50" value=#tripLeader# name="tripLeader" required="Yes" message="A trip leader must be specified."> </td> </tr> <!--- Field: photo ---> <tr> <td valign="top"> Photo File Name </td> <td> <cfinput maxlength="50" size="50" value=#photo# name="photo" required="Yes" message="Valid photo file name must be specified."> </td> </tr> </table> <p> <input type="submit" value="Save"> <input type="submit" value="Cancel" name="btnCancel"> <cfif #tripIdentifier# NEQ ''> <cfinput PASSTHROUGH="ReadOnly" name="tripID" size = 1 maxLength= 7 value=#TripQuery.tripID#> </cfif> </cfform> </body> </html> <!--- Macromedia ColdFusion(r) 6.0 - Getting Started Code Examples ---> <!--- Action Page to edit and save Trip information for Compass Travel. ---> <!--- Create local variable to hold results of business rules test. ---> <CFSET isOk = "Yes"> <!--- Set the depositRequired variable to No if it is not set ---> <cfif not isdefined("Form.depositRequired")> <cfset form.depositRequired = "No"> </cfif> <!--- Trip Name is Required ---> <cfif Form.tripName EQ ""> <CFSET IsOk = "No"> <cfoutput>Trip name cannot be blank.</cfoutput> </cfif> <!--- Trip Leader is Required ---> <cfif Form.tripLeader EQ ""> <CFSET IsOk = "No"> <cfoutput>A trip leader must be specified.</cfoutput> </cfif> <!--- Photo file name is Required ---> <cfif Form.photo EQ ""> <CFSET IsOk = "No"> <cfoutput>Photo file name must be specified.</cfoutput> </cfif> <!--- Number of people is Required and must be Numeric ---> <cfif Form.numberPeople EQ "" or IsNumeric(Form.numberPeople) EQ False> <CFSET IsOk = "No"> <cfoutput>The number of people must be a number and cannot be blank.</cfoutput> </cfif> <!--- Trip location is Required ---> <cfif Form.tripLocation EQ ""> <CFSET IsOk = "No"> <cfoutput>Trip location cannot be blank.</cfoutput> </cfif> <!--- Base Cost is Required and must be Numeric ---> <cfif Form.baseCost EQ "" or IsNumeric(Form.baseCost) EQ False> <CFSET IsOk = "No"> <cfoutput>Base cost must be a number and cannot be blank.</cfoutput> <cfelse> <!--- Price must be 20% greater than Base Cost ---> <cfif Form.basecost * 1.2 GT #Form.price#> <CFSET IsOk = "No"> <cfoutput>Price must be marked up at least 20% above cost.</cfoutput> </cfif> </cfif> <!--- Price is Required and must be numeric ---> <cfif Form.price EQ "" or IsNumeric(Form.baseCost) EQ False> <CFSET IsOk = "No"> <cfoutput>Price must be a number and cannot be blank.</cfoutput> <cfelse> <!--- A deposit is required when the price is > $750 ---> <cfif Form.price GT 750 AND Form.depositRequired EQ "No"> <CFSET IsOk = "No"> <cfoutput>Deposit is required for trips priced over $750.</cfoutput> </cfif> </cfif> <html> <head> <title>Trip Maintenance Confirmation</title> </head> <body> <!--- Check if that all business rules edits were passed. ---> <cfif form.departureDate GT form.returnDate> <CFSET isOk = "No"> <cfoutput>Departure date cannot precede return date. Please re-enter.</cfoutput> </cfif> <!--- Check if that all business rules edits were passed. ---> <cfif isOk EQ "Yes"> <h1>Trip Added</h1> <!--- Database Insert logic goes here. ---> <cfoutput>You have added #Form.TripName# to the trips database. </cfoutput> </cfif> </body> </html> <!--- Action Page to edit and save Trip information for Compass Travel. ---> <!--- Single field edits have been removed in favor of client-side edits. ---> <!--- Make the passportRequired variable be No if it is not set (check box is empty) ---> <CFSET isOk = "Yes"> <cfif not isdefined("Form.depositRequired")> <cfset form.depositRequired = "No"> </cfif> <cfif Form.price GT 750 AND Form.depositRequired EQ "No"> <CFSET IsOk = "No"> <cfoutput>Deposit is required for trips priced over $750.</cfoutput> </cfif> <cfif Form.basecost * 1.2 GT #Form.price#> <CFSET IsOk = "No"> <cfoutput>Price must be marked up at least 20% above cost.</cfoutput> </cfif> <cfif form.departureDate GT form.returnDate> <CFSET isOk = "No"> <cfoutput>Return date cannot precede departure date. Please re-enter.</cfoutput> </cfif> <html> <head> <title>Trip Maintenance Confirmation</title> </head> <body> <cfif isOk EQ "Yes"> <h1>Trip Added</h1> <cfoutput>You have added #Form.TripName# to the trips database. </cfoutput> </cfif> </body> </html> <!--- Action Page to edit and save Trip information for Compass Travel. ---> <!--- Make the passportRequired variable be No if it is not set (check box is empty) ---> <!--- CANCEL BUTTON ---> <cfif IsDefined("Form.btnCancel")> <cfif IsDefined("Form.RecordID")> <cflocation url="tripdetail.cfm?ID=#Form.RecordID#"> <cfelse> <cflocation url="tripdetail.cfm"> </cfif> <cfelse> <!-- Process Save button --> <cfset isOk = "Yes"> <!-- Check to see if photo file exists --> <cfset PhotoLocation = "C:\Inetpub\wwwroot\CFDOCS\getting_started\Photos\"> <cfset PhotoLocation = PhotoLocation & FORM.photo> <cfif not FileExists(PhotoLocation)> <cfoutput>Trip Photo does not exist</cfoutput> <cfset isOk = "No"> </cfif> <cfif isdefined("Form.depositRequired")> <cfset form.depositRequired = "Yes"> <cfelse> <cfset form.depositRequired = "No"> </cfif> <cfif form.price GT 750 AND form.depositRequired EQ "No"> <cfset IsOk = "No"> <cfoutput>Deposit is required for trips priced over $750.</cfoutput> </cfif> <cfif form.basecost * 1.2 GT form.price> <cfset IsOk = "No"> <cfoutput>Price must be marked up at least 20% above cost.</cfoutput> </cfif> <cfif form.departureDate GT form.returnDate> <cfset isOk = "No"> <cfoutput>Return date cannot precede departure date. Please re-enter.</cfoutput> </cfif> <!-- Update the database --> <cfif isOk EQ "Yes"> <cfif isdefined("form.tripID")> <cfupdate datasource="CompassTravel" tablename="TRIPS"> <cflocation url="tripdetail.cfm?ID=#Form.tripID#"> <cfelse> <cfinsert datasource="CompassTravel" tablename="TRIPS"> <cflocation url="tripdetail.cfm"> </cfif> </cfif> <cfoutput>You have added #Form.TripName# to the trips database. </cfoutput> </cfif> <!--- 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><html> <head> <title>Trip Maintenance - Search Form</title> </head> <body> <img src="images/tripsearch.gif"> <!--- Search form ---> <form action="tripsearchresult.cfm" method="post"> <table> <!--- Field: tripLocation ---> <tr> <td> Trip Location </td> <td> <select name="tripLocationOperator"> <option value="EQUALS">is <option value="BEGINS_WITH">begins with </select> </td> <td> <input type="text" name="tripLocationValue"> </td> </tr> <!--- Field: departureDate ---> <tr> <td> Departure Date </td> <td> <select name="departureOperator"> <option value="EQUALS">is <option value="BEFORE">before <option value="AFTER">after </select> </td> <td> <input type="text" name="departureValue"> </td> </tr> <!--- Field: price ---> <tr> <td>Price </td> <td> <select name="priceOperator"> <option value="EQUAL">is <option value="GREATER">greater than <option value="SMALLER">smaller than </select> </td> <td> <input type="text" name="priceValue"> </td> </tr> </table> <p> <input type="submit" value="Search"> </form> </body> </html><!--- Create Where clause for query from data entered thru search form ---> <cfset WhereClause = " 0=0 "> <!--- Query returning search results ---> <!--- Build subclause for trip location ---> <cfif Form.tripLocationValue GT ""> <cfif Form.tripLocationOperator EQ "EQUALS"> <cfset WhereClause = WhereClause & " and tripLocation = '" & form.tripLocationValue & "'" > <cfelse> <cfset WhereClause = WhereClause & " and tripLocation like '" & form.tripLocationValue & "%'" > </cfif> </cfif> <cfquery name="TripResult" datasource="CompassTravel"> SELECT tripName, tripLocation, departureDate, returnDate, price, tripID FROM trips WHERE #PreserveSingleQuotes(WhereClause)# </cfquery> <html> <head> <title>Trip Maintenance - Search Results</title> </head> <body> <img src="images/tripsearchresults.gif"> <table border="0" cellpadding="3" cellspacing="0"> <tr bgcolor="Gray"> <td> Trip Name </td> <td> Location </td> <td> Departure Date </td> <td> Return Date </td> <td> Price </td> </tr> <cfoutput query="TripResult"> <tr> <td> #tripName# </td> <td> #tripLocation# </td> <td> #departureDate# </td> <td> #returnDate# </td> <td> #price# </td> </tr> </cfoutput> </table> </body<!--- 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><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="LASTUPDATED" content="04/10/02 17:19:59"> <script language="JavaScript"> <!--Hide JavaScript if (navigator.appName == "Netscape"){ document.write('<LINK REL=STYLESHEET HREF="../newton_ns.css" TYPE="text/css">'); } else{ document.write('<LINK REL=STYLESHEET HREF="../newton_ie.css" TYPE="text/css">'); } //--> </script> <SCRIPT src="../newton.js" type="text/javascript"></SCRIPT> <title>Adding and Updating SQL Data</title> <!-- <p><span class="heading1">Adding and Updating SQL Data</span></p> --> </head> <body> <div class="navigation"> <table> <tr valign="bottom"> <td width="90%" align="left" valign="bottom" nowrap><em>Getting Started Building ColdFusion MX Applications</em></td> <td align="right" width="10%" valign="bottom" nowrap> <a href="implement_browse_maintenance3.html"><IMG alt="Previous" border="0" height="16" src="../images/icons/back.gif" width="16"></a> <a href="contents.htm" target="_top"><IMG alt="Up" border="0" height="16" src="../images/icons/uplevel.gif" width="16"></A> <a href="add_update2.html"><IMG alt="Next" border="0" height="16" src="../images/icons/next.gif" width="16"></a> <a href="../dochome.htm" target="_top"><IMG alt="Home" border="0" height="16" src="../images/icons/home.gif" width="16"></a> <a href="javascript:top.perdido.document.searchApplet.makeAppear();"><IMG alt="Search" border="0" height="16" src="../images/icons/search.gif" width="16"></a> </td> </tr> <tr align="left" valign="top"> <td colspan="2"> <hr> </td> </tr> </table> </div> <h1 id="1141000"> <a name="1141000"> </a>Lesson 6<br />Adding and Updating SQL Data</h1> <p id="1152366" class="Body"> <a name="1152366"> </a>In this lesson, you will complete the Compass Travel Trip Maintenance application. The exercises will guide you through the steps of adding the database update logic to add new trip offerings and update existing trips in the Compass Travel database. </p> <p id="1155293" class="Body"> <a name="1155293"> </a>This lesson explains how to do the following tasks: </p> <ul> <li>Modify the Trip Edit page to link the add and update functions to the main application page. </li> <li>Write code to insert new trips using SQL. </li> <li>Write code to insert new trips without using SQL.</li> <li>Write code to update several records in the Trips table.</li> </ul><h4 id="1152376" class="Heading4"> <a name="1152376"> </a>ColdFusion tags and functions introduced in this lesson </h4> <p id="1152377" class="Body"> <a name="1152377"> </a>The following table identifies the ColdFusion tags and functions that you use in this lesson to enhance the ColdFusion application: </p> <p id="1152466" class="Body"> <a name="1152466"> </a> <table border="1" cellpadding="5" cellspacing="0"> <caption></caption> <tr valign="top"> <th align="left"><a name="1154694"> </a><div id="1154694" class="CellHeading">Element</div></th> <th align="left"><a name="1154696"> </a><div id="1154696" class="CellHeading">Type</div></th> <th align="left"><a name="1154698"> </a><div id="1154698" class="CellHeading">Description</div></th> </tr> <tr valign="top"> <td align="left"><a name="1154700"> </a><div id="1154700" class="CellBody">cfinsert</div></td> <td align="left"><a name="1154702"> </a><div id="1154702" class="CellBody">Tag</div></td> <td align="left"><a name="1154704"> </a><div id="1154704" class="CellBody">Inserts records in a JDBC data source.</div></td> </tr> <tr valign="top"> <td align="left"><a name="1154706"> </a><div id="1154706" class="CellBody">cfupdate</div></td> <td align="left"><a name="1154708"> </a><div id="1154708" class="CellBody">Tag</div></td> <td align="left"><a name="1154710"> </a><div id="1154710" class="CellBody">Updates a records in a JDBC data source.</div></td> </tr> </table> </p> <p id="1152558" class="Body"> <a name="1152558"> </a> </p> <div class="navigation"> <table> <tr valign="bottom"> <td class="copy" width="90%" align="left" valign="bottom" nowrap> <a href="../copyright.htm">Copyright © 2002, Macromedia Inc. All rights reserved.</a></td> <td align="right" width="10%" valign="bottom" nowrap> <a href="implement_browse_maintenance3.html"><IMG alt="Previous" border="0" height="16" src="../images/icons/back.gif" width="16"></a> <a href="contents.htm" target="_top"><IMG alt="Up" border="0" height="16" src="../images/icons/uplevel.gif" width="16"></A> <a href="add_update2.html"><IMG alt="Next" border="0" height="16" src="../images/icons/next.gif" width="16"></a> <a href="../dochome.htm" target="_top"><IMG alt="Home" border="0" height="16" src="../images/icons/home.gif" width="16"></a> <a href="javascript:top.perdido.document.searchApplet.makeAppear();"><IMG alt="Search" border="0" height="16" src="../images/icons/search.gif" width="16"></a> </td> </tr> </table> </div> <h2>Comments</h2> <FORM ACTION="http://livedocs.macromedia.com/cfmxdocs/Getting_Started_Building_ColdFusion_MX_Applications/add_update.jsp" target="_livedocs"> <INPUT TYPE="Submit" VALUE="View comments on LiveDocs" ALT="View comments on LiveDocs"> </FORM> </body> </html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="LASTUPDATED" content="04/10/02 17:19:59"> <script src="../newton.js" type="text/javascript"></script> <script language="JavaScript"> <!--Hide JavaScript if (navigator.appName == "Netscape"){ document.write('<LINK REL=STYLESHEET HREF="../newton_ns.css" TYPE="text/css">'); } else{ document.write('<LINK REL=STYLESHEET HREF="../newton_ie.css" TYPE="text/css">'); } //--> </script> <title>Completing the Trip Maintenance application </title> <!-- <p><span class="heading1">Completing the Trip Maintenance application </span></p> --> </head> <body> <div class="navigation"> <table> <tr valign="bottom"> <td width="90%" align="left" valign="bottom" nowrap><em>Getting Started Building ColdFusion MX Applications</em> </td> <td align="right" width="10%" valign="bottom" nowrap> <a href="add_update.html"><IMG alt="Previous" border="0" height="16" src="../images/icons/back.gif" width="16"></a> <a href="add_update.html"><IMG alt="Up One Level" border="0" height="16" src="../images/icons/uplevel.gif" width="16"></A> <a href="get_startedIX.html"><IMG alt="Next" border="0" height="16" src="../images/icons/next.gif" width="16"></a> <a href="../dochome.htm" target="_top"><IMG alt="Home" border="0" height="16" src="../images/icons/home.gif" width="16"></a> <a href="javascript:top.perdido.document.searchApplet.makeAppear();"><IMG alt="Search" border="0" height="16" src="../images/icons/search.gif" width="16"></a> </td> </tr> <tr align="left" valign="top"> <td colspan="2"> <hr> <b>Adding and Updating SQL Data</b> </td> </tr> </table> </div> <br> <br> <h1 class="Heading1"> <a name="1152662"> </a>Completing the Trip Maintenance application</h1> <p id="1158551" class="Body"> <a name="1158551"> </a>In <a href="implement_browse_maintenance.html#1141005"></a>, you created the tripeditaction.cfm page to contain server side edits for the trip edit data entry form. In this final lesson, you will complete the tripeditaction.cfm page. To complete the action page, you will write code to do these tasks: </p> <ul> <li>Add trips to the Compass Travel database using the cfquery tag and the SQL INSERT statement. </li> <li>Add trips to the Compass Travel database using the <code>cfinsert</code> tag.</li> <li>Update the current trip using the <code>cfupdate</code> tag.</li> <li>Link the current trip to be updated or added by the tripeditaction.cfm with the tripedit.cfm page.</li> </ul><p id="1159138" class="Body"> <a name="1159138"> </a>In addition to completing the Trip Maintenance application, you will develop a ColdFusion page to update all the prices in the database using the cfquery tag and the SQL UPDATE statement. </p> <h2 id="1152665" class="Heading2"> <a name="1152665"> </a>Writing code to save new trips to the database </h2> <p id="1158605" class="Body"> <a name="1158605"> </a>In <a href="implement_browse_maintenance.html#1141005"></a>, you built a Trip Edit page to collect the data. Now you can modify the Trip Edit action page to insert the data into the database. There are two approaches to inserting data into a SQL database: </p> <ul> <li>Build a SQL INSERT statement and execute it using the <code>cfquery</code> tag. </li> <li>Use the ColdFusion <code>cfinsert</code> tag. This approach eliminates the need for you to learn SQL syntax.</li> </ul><h3 id="1158597" class="Heading3"> <a name="1158597"> </a>Adding data using SQL INSERT with cfquery approach </h3> <p id="1158563" class="Body"> <a name="1158563"> </a>In previous lessons, you used the SQL SELECT statement to retrieve data and the SQL DELETE statement to delete data from the Trips table in the Compass Travel database. To add new trips to the database using SQL, you must understand the syntax of the SQL INSERT statement. </p> <p id="1152666" class="Body"> <a name="1152666"> </a>The SQL INSERT statement inserts new rows into a relational table. The format of the INSERT statement is as follows: </p> <pre>INSERT INTO table_name </pre><pre>VALUES (value1, value2,....) </pre><p id="1152669" class="Body"> <a name="1152669"> </a>The database table named Clients contains information about people in the following rows: <table border="1" cellpadding="5" cellspacing="0"> <caption></caption> <tr valign="top"> <th align="left"><a name="1152672"> </a><div id="1152672" class="CellHeading">LastName</div></th> <th align="left"><a name="1152674"> </a><div id="1152674" class="CellHeading">FirstName</div></th> <th align="left"><a name="1152676"> </a><div id="1152676" class="CellHeading">Address</div></th> <th align="left"><a name="1152678"> </a><div id="1152678" class="CellHeading">City</div></th> </tr> <tr valign="top"> <td align="left"><a name="1152680"> </a><div id="1152680" class="CellBody">Tom</div></td> <td align="left"><a name="1152682"> </a><div id="1152682" class="CellBody">Jones</div></td> <td align="left"><a name="1152684"> </a><div id="1152684" class="CellBody">12 State St</div></td> <td align="left"><a name="1152686"> </a><div id="1152686" class="CellBody">Boston</div></td> </tr> <tr valign="top"> <td align="left"><a name="1152688"> </a><div id="1152688" class="CellBody">Peter</div></td> <td align="left"><a name="1152690"> </a><div id="1152690" class="CellBody">Green</div></td> <td align="left"><a name="1152692"> </a><div id="1152692" class="CellBody">1 Broadway</div></td> <td align="left"><a name="1152694"> </a><div id="1152694" class="CellBody">New York</div></td> </tr> </table> </p> <p id="1152696" class="Body"> <a name="1152696"> </a>After the following SQL statement executes: </p> <pre>INSERT INTO Clients </pre><pre>VALUES ('Smith', 'Kaleigh', '14 Greenway', 'Windham') </pre><p id="1152699" class="Body"> <a name="1152699"> </a>the table contains the following rows: <table border="1" cellpadding="5" cellspacing="0"> <caption></caption> <tr valign="top"> <th align="left"><a name="1152702"> </a><div id="1152702" class="CellHeading">LastName</div></th> <th align="left"><a name="1152704"> </a><div id="1152704" class="CellHeading">FirstName</div></th> <th align="left"><a name="1152706"> </a><div id="1152706" class="CellHeading">Address</div></th> <th align="left"><a name="1152708"> </a><div id="1152708" class="CellHeading">City</div></th> </tr> <tr valign="top"> <td align="left"><a name="1152710"> </a><div id="1152710" class="CellBody">Tom</div></td> <td align="left"><a name="1152712"> </a><div id="1152712" class="CellBody">Jones</div></td> <td align="left"><a name="1152714"> </a><div id="1152714" class="CellBody">12 State St</div></td> <td align="left"><a name="1152716"> </a><div id="1152716" class="CellBody">Boston</div></td> </tr> <tr valign="top"> <td align="left"><a name="1152718"> </a><div id="1152718" class="CellBody">Peter</div></td> <td align="left"><a name="1152720"> </a><div id="1152720" class="CellBody">Green</div></td> <td align="left"><a name="1152722"> </a><div id="1152722" class="CellBody">1 Broadway</div></td> <td align="left"><a name="1152724"> </a><div id="1152724" class="CellBody">New York</div></td> </tr> <tr valign="top"> <td align="left"><a name="1152726"> </a><div id="1152726" class="CellBody">Smith</div></td> <td align="left"><a name="1152728"> </a><div id="1152728" class="CellBody">Kaleigh</div></td> <td align="left"><a name="1152730"> </a><div id="1152730" class="CellBody">14 Greenway</div></td> <td align="left"><a name="1152732"> </a><div id="1152732" cl