Skip to main content
Inspiring
June 30, 2008
Answered

multiple select box into db

  • June 30, 2008
  • 2 replies
  • 371 views
i have a select box that needs to allow for multple selections.
<select name="location_id" multiple="yes" size="4">
<CFLOOP QUERY="get_locations">
<OPTION VALUE="#qry_location_id#"<CFIF qry_location_id EQ location_id> SELECTED</CFIF>>#qry_name#</OPTION>
</CFLOOP>
</select>

i need to write each of the selections into separate rows of my sql table tho, and cannot figure out how to do this. loop statements are breaking and normal insert queries are trying to write all the values into one row and breaking as well.

help is GREATLY appreciated!
This topic has been closed for replies.
Correct answer sirtcarlos
actually was able to solve my query issue in case someone in the future has this problem, here was my loop/insert statement:

<CFLOOP INDEX="ListLocation" LIST="#form.location_id#">
<CFQUERY NAME="#ListLocation#" DATASOURCE="sourcepath">
INSERT INTO tablename (location_id)
VALUES (#ListLocation#)
</CFQUERY>
</CFLOOP>



2 replies

sirtcarlosAuthorCorrect answer
Inspiring
July 2, 2008
actually was able to solve my query issue in case someone in the future has this problem, here was my loop/insert statement:

<CFLOOP INDEX="ListLocation" LIST="#form.location_id#">
<CFQUERY NAME="#ListLocation#" DATASOURCE="sourcepath">
INSERT INTO tablename (location_id)
VALUES (#ListLocation#)
</CFQUERY>
</CFLOOP>



Inspiring
July 1, 2008
The good news is that writing all the values to one row didn't work because that results in unusable data. What loops did you attempt and in which way did they break?
Inspiring
July 2, 2008
Dan,
I tried to put a <CFLOOP> around the <CFQUERY> that inserts the data into the table. (When I take the loop out, and only select 1 item, it does write to the table successfully.)
I think perhaps my problem with the loop is that I'm not sure what I should be indexing.
If you know how I should be doing this properly I will take any advice!
Thanks again for all help!