Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 713

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
<html>
<head>
<title>Retrieving Employee Data Based on Criteria from Form</title>
</head>
<body>
<cfquery name="GetEmployees" datasource="cfdocexamples">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName=<cfqueryparam value="#Form.LastName#"
CFSQLType="CF_SQL_VARCHAR">
</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>
Save the page as actionpage.cfm in the myapps directory.
2
3
View the formpage.cfm page in your browser.
Enter data, for example, Smith, in the Last Name box and submit the form.
4
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".
Click Back in your browser to redisplay the form.
5
Remove the check mark from the check box and submit the form again.
6
This time an error occurs because the check box does not pass a variable to the action page. For information on
modifying the actionpage.cfm page to fix the error, see
Reviewing the code
The following table describes the highlighted code and its function:
Code
<cfquery
name="GetEmployees"datasource="cfdocexamples">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName=<cfqueryparam
value="#Form.LastName#" CFSQLType="CF_SQL_VARCHAR">
<cfoutput query="GetEmployees">
"Testing for a variable's
Description
Queries the data source cfdocexamples and names the query
GetEmployees.
Retrieves the FirstName, LastName, and Salary fields from the
Employee table, but only if the value of the LastName field matches
what the user entered in the LastName text box in the form on
formpage.cfm.
Displays results of the GetEmployees query.
Last updated 1/20/2012
existence" on page 709.
708

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents