表單提交後,調用javascript函數。 JS檢查是否有任何數據輸入到字段中。成功時,加載此CF頁面。該頁面是ajax負載,這就是爲什麼我沒有使用#form.value#。sql in Coldfusion中從oracle中選擇
查詢是什麼搞砸了我。
<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>
爲什麼不工作我的查詢:我已經通過了代碼的其餘部分多次,有當itemtitle行被添加到查詢錯誤是唯一的時間運行?再次,我已經檢查過表單submit,js函數和coldfusion語法都是有效的。只有當這行被添加到查詢中時,它纔會中斷。謝謝。
itemtitle的值是否包含單引號?否則,你會從Oracle得到一個語法錯誤。另外,你會得到什麼錯誤?如果你不容易看到,要麼使用Fiddler觀看AJAX調用,要麼你只從CF獲得500錯誤,嘗試添加檢查日誌或在代碼頂部插入
barnyr
2012-08-03 12:28:37
您也可以考慮在此查詢中使用cfqueryparam,因爲它有助於消除輸入 – barnyr 2012-08-03 12:29:39