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 can specify the columns for which you want to insert data. This approach lets
you insert data to some columns while omitting others. The syntax for this approach is as follows:
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
For example, the syntax to add Kaleigh Smith of Windham, with the address unknown, you use
the named column approach:
INSERT INTO Clients (LastName, FirstName, City)
VALUES ('Smith', 'Kaleigh', 'Windham')
You used the
cfquery
tag to execute SQL from ColdFusion. The
cfquery
tag passes SQL
statements to your data source. As described in
Chapter 4, “Configuring Your Development
Environment,” on page 37
, a data source stores information about how to connect to an indicated
data provider, such as a relational database management system. The data source you established
in that chapter stored information on how to access the Compass Travel database. The data
source name was “CompassTravel”.
Exercise: insert trip data using SQL INSERT and cfquery
In this exercise you will add code to pass the data entered on the Trip Maintenance collection
form and insert into the Compass Travel database. To do this, you will be modifying the trip
insert action page to use the SQL INSERT statement and the ColdFusion
cfquery
tag.
To add data using SQL INSERT and cfquery:
1
Open tripeditaction.cfm in the my_app directory in your editor.
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 to insert the data from the Form variables into the Trips
table.
LastName
FirstName
Address
City
Tom
Jones
12 State St
Boston
Peter
Green
1 Broadway
New York
Smith
Kaleigh
14 Greenway
Windham
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...