Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Location
    denver, CO
    Posts
    4

    Question Unanswered: 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

  2. #2
    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.

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •