Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple Select Entry into DB

Posted on 2001-06-17
7
Medium Priority
?
136 Views
Last Modified: 2013-12-24
I have a good question.  I have a multiple Select box that the user chooses one or more item from.  The items selected are then to be inserted into a DB table.  Currently it is working, although not the way I want.  Now, when I enter the select into the DB, it enters ONE record such as "Item1, Item2, Item 3, etc."  I would like EACH Item to be entered into the DB as it's own record.  Has any one done this?  I know it may involve parsing and Looping, but I'm too new to Coldfusion to know exactly.

Any Ideas?
0
Comment
Question by:khagen
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6199911
When someone selects multiple items from a select box the values are sent as a comma separated list. If you want to loop over this list and enter the records into your database you can do it quite easily as follows:

<CFLOOP list="#form.selectfield#" index="i">
<CFQUERY DATASOURCE="dsn">
INSERT INTO mytable
(column1,column2,column3)
VALUES
('#form.field1#','#form.field2#','#Evaluate('form.' & i)#')
</CFQUERY>

This assumes that the form fields are all text fields in the database and that you want to put the same data for fields1 and 2 into the database for each value that was selected in the select box.

If you want to only insert the values from the select box you can do the following:

<CFLOOP list="#form.selectfield#" index="i">
<CFQUERY DATASOURCE="dsn">
INSERT INTO mytable
(column)
VALUES
('#Evaluate('form.' & i)#')
</CFQUERY>

You need to replace the names of the form fields, datasource and columns in the database from these examples, but otherwise it should work.

Spike
0
 
LVL 1

Author Comment

by:khagen
ID: 6199946
Thanks CF Spike,
But I am Getting an Error,

Here is my Code,
<CFLOOP list="#form.SkillSet#" index="i">
          <CFQUERY DATASOURCE="DataSource">
          Insert into SkillSet(Skill, StaffingID)
          Values('#Evaluate('form.' & i)#', '#Session.StaffingID#')
          </CFQUERY>
          </CFLOOP>

The Error is;

An error occurred while evaluating the expression:
#Evaluate('form.SkillSet' & i)#

An error has occurred while processing the expression:

   form.SkillSet10 KEY BY TOUCH


Invalid parser construct found on line 1 at position 17. ColdFusion was looking at the following text:

KEY


0
 
LVL 1

Author Comment

by:khagen
ID: 6199959
form.SkillSet10 KEY BY TOUCH

SkillSet is the name of the Select, and "10 KEY BY TOUCH" is the first of several selected items.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 5

Accepted Solution

by:
Yog earned 860 total points
ID: 6199970
try this

<CFLOOP list="#form.SkillSet#" index="i">
 <CFQUERY DATASOURCE="DataSource">
 Insert into SkillSet(Skill, StaffingID)
 Values('#i#', '#Session.StaffingID#')
 </CFQUERY>
</CFLOOP>

What spike has said is right , but since we looped , we can just specify the index value here

Cheers.
0
 
LVL 1

Author Comment

by:khagen
ID: 6199982
Thank you Yog,
Cf Spike, I wish I could split my points, but, Yog did get me over the Hump.  Thank you both!
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6200032
You're welcome.

For future reference. If you want to split the points you can reduce the points for the current question by half and post a second question saying something like "Points for CF_Spike" then award the points as an answer for that question

Spike
0
 
LVL 5

Expert Comment

by:Yog
ID: 6200635
ur welcome..

or now i guess just post a comment in the Community support topic and ask to split the points, include the question number also..

cheers.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question