After a form submit, javascript function is called. JS checks to see if there is any data entered into the fields. On success, loads this CF page. The page is an ajax load, that is why I’m not using #form.value#.
The query is what is messing me up. I’ve run through the rest of the code multiple times, the only time there is an error is when the itemtitle line is added to the query:
<cfset fieldList = url.searchFields>
<cfset fieldArray = listToArray(fieldList)>
<!--- The fieldArray has the form field names and values in a one-dimensional array
so every odd index is a title and every even index is a value. Hence the step=2 ---
<cfloop index="testing" from="1" to=#ListLen(fieldList)# step="2">
<cfif fieldArray[testing] is 'searchID'>
<cfset itemid = fieldArray[testing + 1]>
<cfoutput>itemid = #itemid#</cfoutput>
</cfif>
<cfif fieldArray[testing] is 'searchName'>
<cfset itemtitle = fieldArray[testing + 1]>
<cfoutput>itemtitle = #itemtitle#</cfoutput>
</cfif>
<cfoutput>#fieldArray[testing]# #fieldArray[testing + 1]#</cfoutput>
</cfloop>
<cfquery name="searchItems" datasource="#thedb#">
SELECT *
FROM spp_items
WHERE avail_mode LIKE '0'
<cfif isDefined('url.categoryID')> AND categoryid = #url.categoryID#</cfif>
<cfif isDefined('itemid')> AND itemid = #itemid#</cfif>
<!--- if I comment this next line out, the query works fine --->
<cfif isDefined('itemtitle')> AND itemtitle LIKE #itemtitle#</cfif>
</cfquery>
Why is my query not working? Again, I have checked that the form submit, js function, and coldfusion syntax are all valid. Only when this line is added to the query does it break. Thanks.
Looking at the code I can’t see where you are adding quotes around the itemtitle value, it looks like you are currently executing a line which looks like:
instead of: