Solved

Multiple Select Entry into DB

Posted on 2001-06-17
7
129 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Accepted Solution

by:
Yog earned 215 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
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 integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now