Having a CF coding problem, so I thought I might post it here for our developers and clients. Basically, I need to access the value of a checkbox using a CFif statement in order to make a dynamic SQL query.
So, the checkbox looks like this:
<form name="form1" method="post" action="">
<input type="checkbox" name="color" value="white">White
...blah blah
</form> |
and the query is as so:
<cfquery name="showmyCards" datasource="#dsn_name#" username="#dsn_login#"
password="#dsn_password#">
select mycards.userID, mycards.CardID, users.username, tblcards.CardTitle
from mycards, users, tblcards
where mycards.userID = users.userID
and mycards.CardID = tblcards.CardID
<cfif color = white>
and tblcards.ColorCode = "W"
</cfif>
ORDER BY users.username
</cfquery>
<cfoutput query="showmyCards">
<li>#username#, #CardTitle#</li>
</cfoutput> |
Now, the problem block of code is
<cfif color = white>
and tblcards.ColorCode = "W"
</cfif> |
If you comment that out, the rest works. Alternatively, I've tried to do this using
<!--- set variables --->
<cfif color1.value EQ true>
<cfset color1 = "White">
<cfelse>
<cfset color1 = "">
</cfif> |
and then
<cfquery name="showmyCards" datasource="#dsn_name#" username="#dsn_login#" password="#dsn_password#">
SELECT mycards.userID, mycards.CardID, users.username, tblcards.CardTitle
FROM mycards, users, tblcards
WHERE mycards.userID = <cfqueryparam value="#users.userID#" cfsqltype="cf_sql_integer">
AND mycards.CardID = <cfqueryparam value="#tblcards.CardID#" cfsqltype="cf_sql_integer">
AND mycards.ColorCode =
<cfif color1 NEQ "">
<cfqueryparam value="#color1#" cfsqltype="cf_sql_char">
AND mycards.ColorCode =
</cfif> |
for my query, but that errors on the 'set variables' section with
Element VALUE is undefined in COLOR1.