View Single Post
Old 08-08-2011, 11:38 PM   PM User | #6
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Ok, cool, I'm glad you got that far.

You have your values in what ColdFusion calls a "list" (values separated by commas, or some other delimiter). You can use the built in list functionality for this. It just depends if your values are numbers, or strings (varchar).

If your values are numbers, you can just directly insert your comma-delimited list directly into your SQL, and they will form a perfectly valid INSERT statement:
Code:
<cfquery datasource="mydsn">
  INSERT INTO myTable ( field1, field2, field3 )
  VALUES ( #form.formfield1# )  <!--- assuming list is like: 1,2,3 --->
</cfquery>
If your values are strings (varchar), then they need quotes for the database. You should be able to do something like this:
Code:
<cfquery datasource="mydsn">
  INSERT INTO myTable ( field1, field2, field3 )
  VALUES ( 
    <cfset numListItems = listLen( form.formfield1 )>
    <cfloop from="1" to="#numListItems# index="i">
      '#listGetAt( form.formfield1, i )#'<cfif i lt numListItems>,</cfif>
    </cfloop>
  )
</cfquery>
Try that and let me know how it goes.
Gjslick is offline   Reply With Quote