User Guide

Table Of Contents
472 Chapter 20: Accessing and Retrieving Data
Reviewing the code
You now display the number of records retrieved in the query. The following table describes the
code and its function:
Query variable notes and considerations
When using query variables, keep the following guidelines in mind:
Reference the query variable within a cfoutput block so that ColdFusion outputs the query
variable value to the page.
Surround the query variable reference with number signs (#) so that ColdFusion knows to
replace the variable name with its current value.
Do not use the cfoutput tag query attribute when you output the RecordCount or
ColumnList property. If you do, you get one copy of the output for each row. Instead, prefix
the variable with the name of the query.
Enhancing security with cfqueryparam
Some DBMSs let you send multiple SQL statements in a single query. However, hackers might
try to modify URL or form variables in a dynamic query by appending malicious SQL statements
to existing parameters. Be aware that there are potential security risks when you pass parameters
in a query string. This can happen in many development environments, including ColdFusion,
ASP, and CGI. Using the
cfqueryparam tag can reduce this risk.
About query string parameters
When you let a query string pass a parameter, ensure that only the expected information is passed.
The following ColdFusion query contains a WHERE clause, which selects only database entries
that match the last name specified in the LastName field of a form:
<cfquery name="GetEmployees" datasource="cfdocexamples">
SELECT FirstName, LastName, Salary
FROM Employee
WHERE LastName='#Form.LastName#'
</cfquery>
Someone could call this page with the following malicious URL:
http://myserver/page.cfm?Emp_ID=7%20DELETE%20FROM%20Employee
Code Description
<cfoutput>
Displays what follows.
The query returned
Displays the text “The query returned”.
#EmpList.RecordCount#
Displays the number of records retrieved in the EmpList query.
records.
Displays the text “records.”
</cfoutput>
Ends the cfoutput block.