If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > URGENT-PLEASE HELP-INSERT multi-select

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-28-03, 19:15
sbishops sbishops is offline
Registered User
 
Join Date: Dec 2003
Location: denver, CO
Posts: 4
Question URGENT-PLEASE HELP-INSERT multi-select

how can insert multi-select items into access database? here is my code, PLEASE HELP.

<form name="become" method="post" action="becomesubmit.asp">
First Name:
<input name="firstName" type="text" size="25">
<br />

Last Name:
<input name="lastName" type="text" size="25">
<br />

What are your favorite colors?
<select name = "favecolors" multiple size = "5">
<option value = "All">All</option>
<option value = "None">None</option>
<option value = "Red">Red</option>
<option value = "Blue">Blue</option>
<option value = "Green">Green</option>
<option value = "Yellow">Yellow</option>
<option value = "Orange">Orange</option>
</select>

<input type="submit" name="submitbutton" value="Submit">
<br />
</form>

becomesubmit.asp:
<% @Language = VBScript %>
<%
Dim first, last, colors(5), connNewPerson, connFaveColor

first = (Request.Form("firstName"))
last = Request.Form("lastName")

SQL = "INSERT INTO personTable(FIRSTNAME, LASTNAME, "
SQL = SQL & ") VALUES ('" & first & "','" & last & "')"

set connNewPerson = server.createobject("ADODB.Connection")connNewPers on.open "userdb"
connNewPerson.execute(SQL)
connNewPerson.close
set connNewPerson = Nothing

'The above works beautifully and creates an auto-numbered primary key in the personTable.

Now to the problem, I need to get their favorite colors, if any, and put "true" or "yes" in the colorTable along with their primary key from the personTable and I don't want an auto-number to be created in colorTable. Follow?

For i = 1 to Request.Form("favecolors").Count
colors(i) = Request.Form("favecolors")
Next

SQLColor = "INSERT INTO colorTable "TRUE" or "YES" for ANY AND/OR ALL COLORS CHOSEN WHERE personTable.personID = colorTable.personID"

Here are the tables:

personTable:
personID | FIRST | LAST |

colorTable:
personID | RED | BLUE | GREEN | YELLOW | ORANGE |

ANY HELP IS APPRECIATED
Reply With Quote
  #2 (permalink)  
Old 01-06-04, 11:06
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
set personID as primary key of colorTable

You can set personID as your primary key of colorTable. Before you execute to insert the colors into colorTable you need to check if the personID exists in the colortable. If it exists, you can not insert the colors into the table since the primary key is unique.
Reply With Quote
  #3 (permalink)  
Old 01-07-04, 18:11
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
Since I believe you're dealing with values separated by a comma and a space, this concept may be of some help too:

Parsing with join and split - 5/9/1999
http://www.4guysfromrolla.com/webtech/050999-1.shtml
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On