
Validating Data Types
95
The following example shows the use of
cfqueryparam
when valid input is given in
the Course_ID variable used as a query parameter. To see what happens when you
use invalid data, substitute a text string such as “test” for the integer 12 in the
cfset
statement.
Note that this example uses the cfsnippets database that is provided with
ColdFusion, not the CompanyInfo database used in most of this book.
<html>
<head>
<title>cfqueryparam Example</title>
</head>
<body>
<h3>cfqueryparam Example</h3>
<cfset course_id=12>
<cfquery name="getFirst" datasource="cfsnippets">
SELECT *
FROM courses
WHERE Course_ID=<cfqueryparam value="#Course_ID#"
cfsqltype="CF_SQL_INTEGER">
</cfquery>
<cfoutput query="getFirst">
<p>
Course Number: #number#<br>
Description: #descript#
</p>
</cfoutput>
</body>
</html>
Reviewing the code
The following table describes the code and its function:
Code
Description
<cfset Course_ID=12>>
Set the course_ID variable to 12.
<cfquery name="getFirst"
DataSource="cfsnippets">
Query the cfsnippets data source and
return the results in the getFirst query
object.
SELECT *
FROM courses
Select all columns from the courses
table.
Содержание 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 ...