Solved

Multiple Select Entry into DB

Posted on 2001-06-17
7
132 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool to email me when a website changes 29 148
ColdFusion Rereplace 3 97
.dwt files not viewable in browser - why? 2 144
ip / url redirect 13 74
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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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 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…

739 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