User Guide

54 Developing Web Applications with ColdFusion
<CFQUERY NAME="
queryname
"
DATASOURCE="
datasourcename
"
>
...
Base SQL statement
<CFIF value operator value >
...
additional SQL
</CFIF>
</CFQUERY>
First, you need to create an input form, which asks for information about several fields
in the Employees table. Instead of entering information in each field, a user may want
to search on certain fields, or even on only one field. To search for data based on only
the fields the user enters in the form, you use CFIF statements in the SQL statement.
To create the input form:
1. Create a new application page in Studio.
2. Enter the following code:
<HTML>
<HEAD>
<TITLE>Input form</TITLE>
</HEAD>
<BODY>
<!--- Query the Employees table to be able to populate the form --->
<CFQUERY NAME="AskEmployees" DATASOURCE="CompanyInfo">
SELECT
FirstName,
LastName,
Salary,
Contract
FROM Employees
</CFQUERY>
<!--- define the action page in the form tag. The form variables will
pass to this page when the form is submitted --->
<FORM ACTION="getemp.cfm" METHOD="post">
<!-- text box -->
<P>
First Name: <INPUT TYPE="Text" NAME="FirstName" SIZE="20"
MAXLENGTH="35"><BR>
Last Name: <INPUT TYPE="Text" NAME="LastName" SIZE="20"
MAXLENGTH="35"><BR>
Salary: <INPUT TYPE="Text" NAME="Salary" SIZE="10" MAXLENGTH="10">
</P>
<!-- check box -->
<P>
Contractor? <input type="checkbox" name="Contract" value="Yes" >Yes
if checked
</P>