MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Summary of COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX

  • Page 1

    Getting started building coldfusion mx applications.

  • Page 2

    Trademarks afterburner, appletace, attain, attain enterprise learning system, attain essentials, attain objects for dreamweaver, authorware, authorware attain, authorware interactive studio, authorware star, authorware synergy, backstage, backstage designer, backstage desktop studio, backstage enter...

  • Page 3: Contents

    3 contents introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 about macromedia coldfusion mx documentation . . . . . . . . . . . . . . . . . . . . . . . 7 documentation set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 4

    4 contents chapter 3: database fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 understanding database basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 what is a relational database? . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 5

    Contents 5 chapter 7: lesson 3: creating a main application page . . . . . . . . . . . . . . . . . 77 enhancing the trip maintenance application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 showing additional trip details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 6

    6 contents.

  • Page 7: Introduction

    7 introduction getting started building coldfusion mx applications is intended for anyone who needs to begin programming in the coldfusion mx development environment. This book includes a tutorial, which uses supporting files that are installed if you chose to install example applications. If you di...

  • Page 8

    8 introduction viewing online documentation all coldfusion mx documentation is available online in html and adobe acrobat portable document format (pdf) files. Go to the documentation home page for coldfusion mx on the macromedia website: www.Macromedia.Com..

  • Page 9: Part I

    Part i welcome to coldfusion part i provides an introduction to coldfusion. It defines coldfusion and provides an overview of the coldfusion markup language (cfml). It also provides generic database concepts, and information about how to prepare your development environment for using the tutorial in...

  • Page 11: Chapter 1

    11 chapter 1 introducing coldfusion mx this chapter introduces the core technologies that are the foundation for macromedia coldfusion mx. In addition, it introduces the basic concepts about coldfusion mx, how it works, and the various components that comprise it. Contents what is coldfusion mx? . ....

  • Page 12

    12 chapter 1: introducing coldfusion mx what is coldfusion mx? Coldfusion mx is a powerful web application server that lets you create robust sites and applications without a long learning curve. Coldfusion mx does not require coding in traditional programming languages (for example, c/c++, java, xm...

  • Page 13

    What is coldfusion mx? 13 interacting with data sources coldfusion applications can interact with any database that supports a jdbc technology-based driver. A jdbc technology-based driver uses an application programming language (api) to execute sql statements to databases on most platforms. However...

  • Page 14

    14 chapter 1: introducing coldfusion mx using coldfusion mx with macromedia flash mx macromedia flash mx is designed to overcome the many limitations of html and solve the problem of providing efficient, interactive, user interfaces for internet applications. Coldfusion mx is designed to provide a f...

  • Page 15: Chapter 2

    15 chapter 2 cfml basics this chapter introduces the basic elements of cfml, including how to create coldfusion pages, and use variables, functions, conditional processing, and form processing. Contents working with coldfusion pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 16

    16 chapter 2: cfml basics working with coldfusion pages as discussed in chapter 1, “introducing coldfusion mx,” on page 11 , coldfusion pages are plain text files that you use to create web applications. You can create your coldfusion applications by writing all the code manually or by using wizards...

  • Page 17

    Working with coldfusion pages 17 to create a coldfusion page: 1 open your editor and create a blank file. 2 enter the following code on the page: hello world, this is a coldfusion page. Today’s date is #dateformat(now())# saving your coldfusion page in order for the coldfusion server to process the ...

  • Page 18

    18 chapter 2: cfml basics the following figure shows the cfpage.Cfm in the browser: 2 do the following tasks: a view the source code that was returned to the browser. In most browsers, you can view the source by right-clicking on page then selecting view source. B compare the browser source code wit...

  • Page 19

    Understanding cfml elements 19 most often the end tag encloses the tag name in brackets and includes a slash (/), like this: the information processed by coldfusion is placed between the start and end tag, like this: info to be processed ... Coldfusion tags, for the most part, share these common cha...

  • Page 20

    20 chapter 2: cfml basics the dollarformat function returns a value as a string and formats that value with two decimal places, thousand separator, and dollar sign. The pounds signs (#) around the function instruct coldfusion to evaluate the content between the pound signs and display the value. Fun...

  • Page 21

    Understanding cfml elements 21 if you did not include the pound signs around the dateformat(now(), "mm/ddyyy") function, coldfusion would not evaluate the function and the previous example would display your source code, as follows: for more information about how to use pound signs with functions, s...

  • Page 22

    22 chapter 2: cfml basics in the following examples, the variables are assigned a string literal value. All string literal values are surrounded by double quotation marks. In the next example, coldfusion uses the values of the my_first_name and my_last_name variables to set the value for the my_full...

  • Page 23

    Working with cfml expressions 23 displaying variable output output is what remains after the coldfusion server processes the cfml tags on a page. Usually the output has two parts: • information that the user sees (for example, a confirmation message) • information that is stored by the server as a r...

  • Page 24

    24 chapter 2: cfml basics building expressions in coldfusion, you build expressions as you need them. The expressions can include simple elements, such as the expressions shown previously, or they can include complex elements, such as arithmetic functions, strings, and decision operators. (you build...

  • Page 25

    Working with cfml expressions 25 specifying quotation marks around values when assigning literal values to variables, you must surround the literal value with double quotation marks or single quotation marks. Coldfusion interprets the content between the quotation marks as a literal value and assign...

  • Page 26

    26 chapter 2: cfml basics arithmetic operators the following table lists the arithmetic operators that coldfusion supports: string operator the following table describes the one coldfusion string operator that is a concatenation operator: understanding conditional processing to this point, all the c...

  • Page 27

    Understanding conditional processing 27 you use conditional processing to customize the behavior of your application. Conditional processing facilitates decision making and lets you control how the code on a page is processed. In coldfusion, you implement conditional processing with flow control tag...

  • Page 28

    28 chapter 2: cfml basics the output of this cfif statement is based on the value entered by the user. If the user enters ma in the state form field, the state tax results returned is 8.5%. If the user enters va in the state form field, the state tax results returned is 8.2%. If the user enters any ...

  • Page 29

    Commenting your code 29 in order for the form page to find its corresponding action page, the action statement in the form tag must be correct. The form tag includes the information that tells the server where to send the data that it collects. It also tells the server how to send it. To processes t...

  • Page 30

    30 chapter 2: cfml basics.

  • Page 31: Chapter 3

    31 chapter 3 database fundamentals this chapter provides a quick overview of relational database concepts and terms. It describes what a database is and how it is organized. It also discusses the structured query language (sql) that you use to interact with databases. Contents understanding database...

  • Page 32

    32 chapter 3: database fundamentals understanding database basics even though you do not need a thorough understanding of database management systems to create coldfusion applications, you must understand some basic concepts and techniques about databases. The information in this chapter will get yo...

  • Page 33

    Understanding database basics 33 understanding relational tables in a database, you can organize data in multiple tables. For example, if you manage a database for the human resource department, you might have one table that lists all the employees information and another table that lists all the de...

  • Page 34

    34 chapter 3: database fundamentals about sql sql (structured query language) is a language that lets you communicate with databases. For example, you can use sql to retrieve data from a database, add data to a database, delete or update records in a database, change columns in multiple rows, add co...

  • Page 35

    Using sql with coldfusion 35 writing sql and cfml statements to interact with a data source after coldfusion makes a connection to the data source, you can interact with that database by using sql and coldfusion. To interact with an established data source, you need to include sql statements in your...

  • Page 36

    36 chapter 3: database fundamentals.

  • Page 37: Chapter 4

    37 chapter 4 configuring your development environment this chapter describes how to set up your development environment for the tutorial in part ii of this book. It specifies the tutorial file structure, and how to configure the database connection and debugging options in the coldfusion mx administ...

  • Page 38

    38 chapter 4: configuring your development environment verifying the tutorial file structure before you begin the tutorial, verify that the configuration of the computer where coldfusion is installed matches the file structure described in the following sections. The files required to complete the c...

  • Page 39

    Configuring database connection and debugging options 39 configuring database connection and debugging options prior to coldfusion development, use the coldfusion mx administrator to define the connection to the sample database file and any optional debugging options. To access the coldfusion admini...

  • Page 40

    40 chapter 4: configuring your development environment 4 specify the following: 5 click show advanced settings and ensure that the settings for clob and blob are enabled (checked). 6 click submit to complete the data source configuration. The coldfusion mx administrator verifies the data source conn...

  • Page 41

    Configuring database connection and debugging options 41 4 specify the following: 5 click show advanced settings to make the following settings: 6 click submit to complete the data source configuration. The name compasstravel appears in the connected data sources dialog box. 7 click verify all conne...

  • Page 42

    42 chapter 4: configuring your development environment enabling debugging options the coldfusion mx administrator provides a variety of debugging settings that let you enable debugging information on a server-wide basis. If you are working on a development system, you can have these options turned o...

  • Page 43

    Configuring database connection and debugging options 43 the location of the debugging information or the type of debugging data shown varies, depending on the options that you enable on the debugging page in the coldfusion mx administrator. In the following example, the debugging output includes ge...

  • Page 44

    44 chapter 4: configuring your development environment sending debugging information to remote clients if you are using a remote client to perform the tutorial in part ii of this book, you must specify your ip address to receive debugging information. If you are working on a local client (the comput...

  • Page 45

    Macromedia development environment tools 45 the dreamweaver mx environment as a coldfusion developer, you can build coldfusion mx applications by writing the code manually or generating the code by using one of the code-generating tools provided with dreamweaver mx. Features for coldfusion developer...

  • Page 46

    46 chapter 4: configuring your development environment configuring dreamweaver mx for coldfusion development before you use dreamweaver mx to create the sample application in part ii of this book, you must configure dreamweaver to recognize the tutorial files and data sources. To configure dreamweav...

  • Page 47: Part II

    Part ii building a coldfusion application part ii provides a tutorial that steps you through building a sample coldfusion application. It consists of six lessons: lesson 1: preparing to build the sample application . . . . . . . . . . . . . . . . . 49 lesson 2: writing your first coldfusion applicat...

  • Page 49: Chapter 5

    49 chapter 5 lesson 1: preparing to build the sample application in this tutorial, you will build a simple coldfusion web application for a fictitious travel company called compass travel. Compass travel markets a wide range of adventure trips to the public through its website. Trip coordinators at ...

  • Page 50

    50 chapter 5: lesson 1: preparing to build the sample application determining the application functional requirements before you can build the sample application, you must understand the functional requirements underpinning its design. The design of the sample application centers around the daily ta...

  • Page 51

    Determining the data requirements 51 determining the data requirements prior to creating the application pages to capture trip information, you must determine what type of data is required about each trip. For the example, in this tutorial, the compass travel trip coordinator must maintain the follo...

  • Page 52

    52 chapter 5: lesson 1: preparing to build the sample application designing the database for your application after you identify the information to collect, you must consider where to store the data. Prior to creating the data collection form and instructing coldfusion where to store the form data, ...

  • Page 53

    Designing the database for your application 53 establishing a relationship between the two tables when the user selects an event type from the list obtained from reading the eventtypes table, the correct event type must be saved to the trips table with all the other trip related data. The applicatio...

  • Page 54

    54 chapter 5: lesson 1: preparing to build the sample application developing the sample application given the application functional requirements and the database provided, you are ready to use coldfusion to develop the trips maintenance application. The remaining lessons in the tutorial will step y...

  • Page 55

    Developing the sample application 55 how to proceed each lesson in the tutorial is designed to let you proceed at your own pace. At any time, you can stop and later return to that place in a lesson so that you can complete all the sections in the lesson. Each lesson guides you through a scenario to ...

  • Page 56

    56 chapter 5: lesson 1: preparing to build the sample application for more information about the tutorial file structure and the location of the getting_started subdirectories, see “verifying the tutorial file structure” on page 38 . Requirements to use this tutorial, you must have the following com...

  • Page 57: Chapter 6

    57 chapter 6 lesson 2: writing your first coldfusion application in this lesson, you begin the construction of a coldfusion web application for the fictitious company, compass travel. The exercises in this lesson guide you through the steps of creating queries and forms to search for and display tri...

  • Page 58

    58 chapter 6: lesson 2: writing your first coldfusion application creating your first coldfusion application as you recall from lesson 1: preparing to build the sample application , two of the requirements for the trip maintenance application are the ability to generate trip listings and a trip quer...

  • Page 59

    Creating your first coldfusion application 59 • trip search results page the purpose of the trip search results page is to display the results of a trip search. The primary users of these components are the compass travel coordinators and agents, not the general public. Application development steps...

  • Page 60

    60 chapter 6: lesson 2: writing your first coldfusion application using a web page to list trips to help compass travel agents take trip reservations by telephone and in person, the trip coordinator maintains a list of current trip offerings. Years ago, the coordinator would type the list and fax it...

  • Page 61

    Using a web page to list trips 61 consider a table named clients to hold information about people with the following rows: to select the columns named lastname and firstname, use the following select statement: select lastname, firstname from clients the result of this sql statement contains the fol...

  • Page 62

    62 chapter 6: lesson 2: writing your first coldfusion application the result of the preceding sql statement contains the following data: you can compose a where clause with one or more conditions; these are called subclauses. You join subclauses using the operators and and or.The and operator displa...

  • Page 63

    Using a web page to list trips 63 displaying the query result using cfoutput in chapter 2, “cfml basics,” on page 15 , you learned that the coldfusion cfoutput tag is an easy mechanism to display literal text and the contents of variables. Additionally, the cfoutput tag significantly simplifies disp...

  • Page 64

    64 chapter 6: lesson 2: writing your first coldfusion application exercise: building a query using sql, cfquery, and cfoutput follow these steps to build a query that lists the current trips from the compass travel database. To build the query: 1 open an editor and create a new coldfusion page (.Cfm...

  • Page 65

    Using a web page to list trips 65 to enhance the query results: 1 to sort the trip names in alphabetical order in the triplisting.Cfm page, modify the sql select statement within the cfquery tags as follows: select tripname from trips order by tripname 2 to display the departure, return date, and pr...

  • Page 66

    66 chapter 6: lesson 2: writing your first coldfusion application developing a search capability the dynamic listings developed in the previous exercise meet many of compass travel’s requirements for locating trips. However, what if the number of trips were in the thousands or tens of thousands? Loc...

  • Page 67

    Developing a search capability 67 understanding search query operators now that you decided on the queryable columns (triplocation, departuredate, and price), you can build a simple form that allows the user to enter values for each of these fields. If the user enters a value (for example, boston) f...

  • Page 68

    68 chapter 6: lesson 2: writing your first coldfusion application using sql operators to create a search criteria page a simple design for a search criteria page presents an operator list and data entry field for each of the queryable columns. Following this pattern, a page to collect the compass tr...

  • Page 69

    Developing a search capability 69 is greater than smaller than reviewing the code the following table describes the search criteria code and its function: building the search results page based on the queryable columns identified earlier, the sql query to display the search results would look like t...

  • Page 70

    70 chapter 6: lesson 2: writing your first coldfusion application when the user enters the search criteria on the trip search form and clicks the search button, the form fields are then posted to the trip search results page. The posted field values compose the where clause in the sql select stateme...

  • Page 71

    Developing a search capability 71 for each search criterion on the trip search form, the code within the trip search results page must do the following: • verify that the user entered data in the search criterion’s value field using the cfif tag; for example • if data was entered, construct a where ...

  • Page 72

    72 chapter 6: lesson 2: writing your first coldfusion application reviewing the code the following table describes the code used to build the triplocation where subclause: note that the preceding code only builds the triplocation subclause. In the following exercise you will add code for the other t...

  • Page 73

    Developing a search capability 73 completing the trip search results page in the following exercises you will test and modify tripsearchresults.Cfm. In the first exercise, you will test the trip search results page by entering criteria on the trip search form and inspecting the results. In the secon...

  • Page 74

    74 chapter 6: lesson 2: writing your first coldfusion application exercise: enabling the departure and price criteria on the trip search form in this exercise you will modify the trip search results page to add the criteria needed for the departure and price query. To enable the departure and price ...

  • Page 75

    Summary 75 4 verify that the price and departuredate are now considered in the query, as in step 4 in the previous exercise: a open the tripsearch.Cfm page in the my_app directory in your browser. B in the departure date drop-down list box, select before, enter 1/1/1900as the date (specify 1900-1-1 ...

  • Page 76

    76 chapter 6: lesson 2: writing your first coldfusion application.

  • Page 77: Chapter 7

    77 chapter 7 lesson 3: creating a main application page in this lesson you will enhance the compass travel trip maintenance application. The exercises in this lesson guide you through the following steps: • transforming the search facility that you built in the previous lesson into a drill-down faci...

  • Page 78

    78 chapter 7: lesson 3: creating a main application page enhancing the trip maintenance application in this lesson you will enhance the trip maintenance application that you created in lesson 2: writing your first coldfusion application . You will modify the application to include a main application...

  • Page 79

    Enhancing the trip maintenance application 79 • enhanced trip search results page the original purpose of the trip search results page in lesson 2: writing your first coldfusion application was to display the results of a trip search. In this lesson, you will enhance this page to provide a useful dr...

  • Page 80

    80 chapter 7: lesson 3: creating a main application page the primary users of these components will be the compass travel coordinators and agents, not the general public. Showing additional trip details by design, the trip search results page displays a subset of the information about a trip. To get...

  • Page 81

    Enhancing the trip maintenance application 81 exercise: building a trip detail page follow these steps to build a trip detail page. To build a trip detail page: 1 open your editor and create a new coldfusion page. Remove any lines that your editor adds. 2 to create a query to select a single trip fr...

  • Page 82

    82 chapter 7: lesson 3: creating a main application page 5 to provide a title that appears on the browser window, insert the following html code before the line: 6 insert the ending body and html tags at the end of the page: 7 save the file as tripdetail.Cfm in the my_app directory. 8 the rio cahabo...

  • Page 83

    Enhancing the trip maintenance application 83 the following page shows the expected result: reviewing the code the following table describes the coldfusion code used to build the trip detail page: code explanation datasource="compasstravel" maxrows=1> the cfquery tag includes a maxrows attribute. Th...

  • Page 84

    84 chapter 7: lesson 3: creating a main application page as you can see, you can build comprehensive database query applications using cfml and dynamic sql. To further test the new trip detail page that you created, you will link it to the search facility that you built in lesson 2: writing your fir...

  • Page 85

    Enhancing the trip maintenance application 85 linking the search results page to the trip detail page in the next exercise you will modify the trip search results page to let the user view the details of any trip. To do this, you will convert the trip name entries in the results page to links, which...

  • Page 86

    86 chapter 7: lesson 3: creating a main application page enhancing the look of the search results and detail pages the trip maintenance search now provides a useful drill-down mechanism for locating trips. While this application is functionally sound, the appearance of the dates and dollar amounts c...

  • Page 87

    Enhancing the trip maintenance application 87 when a query variable is referenced within a cfoutput block, the qualifying query_name is assumed to be the query identified in the query attribute of the cfoutput tag and does not need the qualifier query_name . That is why the currentrow variable is un...

  • Page 88

    88 chapter 7: lesson 3: creating a main application page the trip search results page appears: 5 in the trip search result page, click the link for riding the rockies. The properly formatted trip detail page appears:.

  • Page 89

    Enhancing the trip maintenance application 89 creating the main application page from the trip detail page to this point in the tutorial, you created a very useful drill-down query facility. Compass travel trip coordinators can produce lists required by management and easily locate and display infor...

  • Page 90

    90 chapter 7: lesson 3: creating a main application page note: notice that the current trip record id (tripid) is hidden within the form code. This is desirable because the action page must have the current record id in order to build the query that navigates to the appropriate record in the trips d...

  • Page 91

    Enhancing the trip maintenance application 91 reviewing the code the following table describes the navigation code in the trip detail page: adding database maintenance buttons the search and sequential navigation capabilities are features for locating compass travel trips. After the trip coordinator...

  • Page 92

    92 chapter 7: lesson 3: creating a main application page 3 save the file and view the updated tripdetail.Cfm page in a browser (http://localhost/cfdocs/ getting_started/my_app/tripdetail.Cfm?Id=8). The page appears as follows: 4 click search or delete to test the database maintenance buttons. An err...

  • Page 93: Chapter 8

    93 chapter 8 lesson 4: validating data to enforce business rules in this lesson, you will enhance the compass travel trip maintenance application. The exercises in this lesson will guide you through the steps of enhancing the application to provide a page for the trip coordinator to add new trip off...

  • Page 94

    94 chapter 8: lesson 4: validating data to enforce business rules enhancing the trip maintenance application in this lesson and the next, you will create the code to implement the remaining maintenance buttons on the main trip maintenance application page. The remaining buttons are add and edit. You...

  • Page 95

    Developing code to validate data and enforce business rules 95 exercise: view the source and test the trip edit page to view the source and test the trip edit data collection form: 1 open an editor, then locate and open the file tripedit1.Cfm in the solutions directory \cfdocs\getting_started\soluti...

  • Page 96

    96 chapter 8: lesson 4: validating data to enforce business rules the following table lists the compass travel business rules for capturing and editing trip information. This table identifies which rules require single-field or cross-field editing. Ways to validate data coldfusion provides special t...

  • Page 97

    Developing code to validate data and enforce business rules 97 evaluating check box and radio button variables business rule 8 in the compass travel new trip policy requires you to test the value of the depositrequired check box form variable. Check box and radio button variables are only passed to ...

  • Page 98

    98 chapter 8: lesson 4: validating data to enforce business rules to build trip edit action page and validate data passed: 1 open an editor and create a new page called tripeditaction.Cfm in the my_app directory. The new page appears as follows: 2 to ensure that compass travel business rule 7 is met...

  • Page 99

    Developing code to validate data and enforce business rules 99 6 test various combinations to make sure all the compass travel business rules are enforced by filling out the fields on the form and clicking save. Testing recommendations: ■ leave out required fields, such as trip name or location. ■ e...

  • Page 100

    100 chapter 8: lesson 4: validating data to enforce business rules server-side validation approach (no coldfusion form tag) the following code is on the server (tripeditaction.Cfm page): the number of people must be a number and cannot be blank. Client-side validation approach using coldfusion form ...

  • Page 101

    Developing code to validate data and enforce business rules 101 4 for each coldfusion form tag ( cfinput , and cfselect ), assign the appropriate values: for example, the trip name field requires the following code: message = "trip name must not be blank"> tip: for additional help, review the comple...

  • Page 102

    102 chapter 8: lesson 4: validating data to enforce business rules return date cannot precede departure date. Please re-enter. Cfoutput> you have added #form.Tripname# to the trips database. 7 view the tripedit.Cfm page in a browser and test the client- and server-side field validations by filling o...

  • Page 103

    Developing code to validate data and enforce business rules 103 the cfselect tag the cfselect tag is an improved version of the html select tag. Like other coldfusion form tags, the cfselect tag provides the required and message attributes that validate the data entered. Using the cfselect tag and t...

  • Page 104

    104 chapter 8: lesson 4: validating data to enforce business rules 5 view the tripedit.Cfm page in a browser. Select the event types drop-down list. Notice that all seven event types appear in the list. Using other client-side script to reduce edits on the server if you were interested in moving as ...

  • Page 105

    Developing code to validate data and enforce business rules 105 another reason that rule 6 requires javascript scripting is that it tests the values of more than one field in a single edit. You must ensure that the return date field is greater than departure date field. To do this, you add a javascr...

  • Page 106

    106 chapter 8: lesson 4: validating data to enforce business rules exercise: add javascript-based validation code in this exercise you will modify the trip insert page to validate the departure and return dates using the javascript functions provided. To validate the departure and return dates using...

  • Page 107

    Developing code to validate data and enforce business rules 107 you used the required attribute for the photo cfinput tag to ensure that a filename is entered. Now you must make sure that the file exists in the right directory so the application can display it to customers. Since browser clients are...

  • Page 108

    108 chapter 8: lesson 4: validating data to enforce business rules to verify that the photo filename exists: 1 open the tripeditaction.Cfm in the my_app directory in your editor. 2 in the tripeditaction.Cfm page, do the following: a add logic to check that the user entered a valid photo filename by ...

  • Page 109: Chapter 9

    109 chapter 9 lesson 5: implementing the browsing and maintenance database functions in this lesson, you will enhance the compass travel coldfusion application by providing code to implement the navigation and maintenance database functions. This lesson explains how to do the following tasks: • use ...

  • Page 110

    110 chapter 9: lesson 5: implementing the browsing and maintenance database functions enhancing the trip maintenance application in this lesson, you will make enhancements to the sample trip maintenance application that you created in previous lessons. In lesson 4: validating data to enforce busines...

  • Page 111

    Enhancing the trip maintenance application 111 maintenance action page the maintenance action page processes a user’s maintenance request from the trip detail page. The request can be any of the following actions: • delete the currently displayed trip. • launch the search facility. • add a new trip ...

  • Page 112

    112 chapter 9: lesson 5: implementing the browsing and maintenance database functions limiting the number of result rows each of the sql statements in the previous table return a result set of trips rows. The result set can range from zero to any number of rows. The navigation action page must limit...

  • Page 113

    Enhancing the trip maintenance application 113 reviewing the code the following table describes the code used to process the navigation button requests: exercise: implement trip record browsing (navigation) follow these steps to implement the trip record browsing functionality (navigation buttons) o...

  • Page 114

    114 chapter 9: lesson 5: implementing the browsing and maintenance database functions b click previous row. The trip detail page shows information about the first trip. C click last row. The trip detail page shows information about the last trip. D click first row. The trip detail page shows informa...

  • Page 115

    Enhancing the trip maintenance application 115 deleting the current trip record shown on the trip detail page before you can write the code to delete a trip, you must understand the underlying sql statement to delete rows from the trips table. Sql delete statement the sql delete statement removes ex...

  • Page 116

    116 chapter 9: lesson 5: implementing the browsing and maintenance database functions 3 to handle the search and delete buttons from the trip detail page, enter the following code: delete from trips where tripid = #form.Recordid# 4 save the page as maintenanceaction.Cfm in the my_app directory. 5 vi...

  • Page 117: Chapter 10

    117 chapter 10 lesson 6: adding and updating sql data 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 databa...

  • Page 118

    118 chapter 10: lesson 6: adding and updating sql data completing the trip maintenance application in lesson 5: implementing the browsing and maintenance database functions , you created the tripeditaction.Cfm page to contain server side edits for the trip edit data entry form. In this final lesson,...

  • Page 119

    Completing the trip maintenance application 119 the table contains the following rows: notice that the values inserted in the table were surrounded by single quotation marks. In sql, you must surround any text or date values with single quotation marks but numeric values are not. Alternatively, you ...

  • Page 120

    120 chapter 10: 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 page in your br...

  • Page 121

    Completing the trip maintenance application 121 4 in the tripedit.Cfm page, fill in the fields with the values in the following figure, then click save: after the new trip is written to the database, the following message appears: trip is added. 5 to verify that the save worked, open tripsearch.Cfm ...

  • Page 122

    122 chapter 10: lesson 6: adding and updating sql data 7 click search. The tripresults page appears: 8 click the link to the nh white mountains to display the details of the trip you just added. Verify that all the fields were saved correctly. The following page appears: 9 click the delete button to...

  • Page 123

    Completing the trip maintenance application 123 reviewing the code the following table describes the sql insert and cfquery code used to add data: for more information about adding data to a database using sql and cfquery , see developing coldfusion mx applications. For more information about sql, c...

  • Page 124

    124 chapter 10: lesson 6: adding and updating sql data to add data using cfinsert: 1 open tripeditaction.Cfm from the my_app directory in your editor and do the following: a remove the entire addtrip cfquery that you added in the last exercise (from the beginning tag to the end tag). B add the follo...

  • Page 125

    Completing the trip maintenance application 125 exercise: update trip data using cfupdate in this exercise, you will add the code to update the trip data into the database. You will add the cfupdate tag to the tripeditaction.Cfm page. To update the database using cfupdate: 1 in an editor, open tripe...

  • Page 126

    126 chapter 10: lesson 6: adding and updating sql data notice that when the user clicks the add button, the maintenanceaction.Cfm navigates to tripedit.Cfm passing no arguments. Conversely, when the user clicks the edit button, the trip edit page passes the current record id. The trip edit page must...

  • Page 127

    Completing the trip maintenance application 127 reviewing the code the following table describes the code used to properly initialize the trip edit form: exercise: linking the add and edit buttons in this exercise you will link the add and edit buttons on the trip detail page with the trip edit page...

  • Page 128

    128 chapter 10: lesson 6: adding and updating sql data 9 test update logic by opening the tripdetail.Cfm page in your browser and doing the following tasks: a click the edit button. B double the price of the current trip. C click save. The coldfusion cfupdate works well for updating a single record....

  • Page 129

    Completing the trip maintenance application 129 the table contains the following rows: updating multiple records the cfupdate statement works well when you want to update the current record within a cfquery . Alternatively, you can update several rows within a table by issuing a single query using c...

  • Page 130

    130 chapter 10: lesson 6: adding and updating sql data summary in this lesson you used the cfinsert and cfupdate tags to add and update data to a sql table. You also have used the sql update statement in conjunction with the cfquery tag to effect a trip price increase for all rows in the trips table...

  • Page 131: Index

    131 index a action page, defined 28 application. See tutorial c cfform, defined 93 cfif, defined 57 cfinput, defined 93 cfinsert, defined 117 cflocation, defined 109 cfml basics 15–29 building applications 12–13 commenting code 29 elements 18–23 expressions, described 23–26 functions 19 operators 25...

  • Page 132

    132 index development tools described 13, 44–46 macromedia dreamweaver mx 44 macromedia homesite+ 44 dollarformat function, defined 77 e editors, supported 16 expressions building 24 character case 24 defined 23 denoting functions or variables 24 literal values 25 operators 25 pound signs 24 quotati...

  • Page 133

    Index 133 t tags attributes 19 cfform 93 cfif 57 cfinput 93 cfinsert 117 cflocation 109 cfoutput 57 cfquery 57 cfselect 93 cfset 57 cfupdate 117 defined 18–19 syntax 18 tutorial adding and updating sql data 117–130 application business rules 96 application defined 54 application page flow 110 applic...

  • Page 134

    134 index.