Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiple Select Entry into DB

Posted on 2001-06-17
7
Medium Priority
?
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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 properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

704 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