
46
Chapter 4 Retrieving and Formatting Data
However, instead of putting the LastName directly in the SQL WHERE clause, you
can use the text that the user entered in the form for comparison:
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName="#Form.LastName#"
</cfquery>
For more information on Dynamic SQL, see “Dynamic SQL” on page 96.
Creating action pages
Use the following procedure to create an action page for cormpage.cfm.
To create an action page for the form:
1
Create a new application page in ColdFusion Studio.
2
Enter the following code:
<html>
<head>
<title>Retrieving Employee Data Based on Criteria from Form</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="CompanyInfo">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName=’#Form.LastName#’
</cfquery>
<h4>Employee Data Based on Criteria from Form</h4>
<cfoutput query="GetEmployees">
#FirstName#
#LastName#
#Salary#<br>
</cfoutput>
<br>
<cfoutput>Contractor: #Form.Contractor#</cfoutput>
</body>
</html>
3
Save the page as actionpage.cfm within the myapps directory.
4
View
formpage.cfm
in your browser.
5
Enter data, for example, Smith, in the Last Name box and submit the form.
The browser displays a line with the first and last name and salary for each entry
in the database that match the name you typed, followed by a line with the text
“Contractor: Yes”
6
Click Return in your browser to redisplay the form.
7
Remove the check mark from the check box and submit the form again.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...