Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Query problem - Please Advise

Status
Not open for further replies.

baybook

MIS
Sep 16, 2004
66
US
I have not used CF in some time and I am trying to create some simple queries to pull data based on a value the user selects on a form.

Can someone tell me why the first query below works, but does not work when I add a where clause... My eyes must be going bad.

This works:
<cfquery name="totallist2" datasource="alist">
SELECT *
FROM store_info
ORDER BY store_name
</cfquery>

<cfoutput>
#form.state#<br>
</cfoutput>
<cfoutput query="totallist2">
#store_name# <br>
</cfoutput>

This query does not work. the only difference is the where parameter.

<cfquery name="totallist2" datasource="alist">
SELECT *
FROM store_info where state = #form.state#
ORDER BY store_name
</cfquery>

<cfoutput>
#form.state#<br>
</cfoutput>
<cfoutput query="totallist2">
#store_name# <br>

</cfoutput>
 
Never mind --- after 45 min of playing with this, I tried single quotes and NOW it works.

Thanks for reading this!
 
the only time you don't need single quotes is around a number field, the keyword NULL and functions(i think). Dates don't use single quotes but use # instead.

that means in CF you need to do something like this when working with dates. ###form.mydate###

Beware of programmers who carry screwdrivers.
 
If you use cfqueryparam, like a good little programmer should, you won't have this problem. It takes care of the quotes or non quotes issues for you. [thumbsup2]



Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top