Q&A
Q1: | I've designed an input form that assembles user selections into a list. I want to use the list to create a dynamic query, but my SQL statement requires that each list item appear in single quotes. What to do? |
A1: | When you use the list variable in your query, surround it with the function QuotedValueList, like this:
#QuotedValueList(form.variable)# This will cause ColdFusion to insert single quotes around each item in your list. |
Q2: | How do I guard against errors if my query calls on an empty list, for example, if a user hits "submit" without typing anything into a search box? |
A2: | There are several solutions. The simplest is to use the <CFPARAM> tag on your results page to define a default value for your list. You might also use a <CFIF> ... |
Get Sams Teach Yourself ColdFusion® in 21 Days now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.