System information
Exercise 2: Adding trips with SQL INSERT statements 131
To test the delete capability:
1.
View the tripdetail.cfm page in a browser.
The current trip is Nepal. Notice that the destination for the Nepal Summit Challenge trip is
Imji Himal, Nepal.
2.
Click Search.
The Trip Search page appears.
3.
In the Trip Search page, select Begins With in the selection box for Trip Location.
4.
Enter Imji in the Trip Location field.
5.
Click Search.
6.
Verify that only one trip is found whose location begins with Imji.
7.
To return to the Trip Detail page for this trip, click Nepal Summit Challenge
8.
In the Trip Detail page, click Delete.
9.
Click Search.
10.
Select Beings With in the selection box for Trip Location.
11.
Enter Imji in the Trip Location field.
12.
Click Search.
There should be no records, because you deleted the trip.
Exercise 2: Adding trips with SQL INSERT statements
In “Lesson 8: Implementing Browsing and Searching” on page 123, 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:
• Build a SQL INSERT statement and execute it using the cfquery tag.
• Use the ColdFusion cfinsert tag. This approach eliminates the need for you to learn SQL
syntax.
In this exercise, you use a SQL INSERT statement.
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.
The SQL INSERT statement inserts new rows into a relational table. The SQL INSERT
statement has the following format:
INSERT INTO table_name
VALUES (value1, value2,....)