array query with multiple <SELECT> form field

Discussion in 'ASP General' started by Burton Figg, Jan 18, 2004.

  1. Burton Figg

    Burton Figg Guest

    I have a SELECT statement which holds a list of times (for adding
    appointments to a database):

    e.g.

    <select name="time" id="time" size="3" multiple>
    <option value="00:00">00:00</option>
    <option value="00:30">00:30</option>
    <option value="01:00">01:00</option>
    <option value="01:30">01:30</option>
    <option value="02:00">02:00</option>
    <option value="02:30">02:30</option>
    </select>

    on the process page, I want to loop through the values of the "time" select
    field, and enter them into a database.

    I have tried this:

    strSubject = request.Form("subject")
    strDate = request.Form("theDate")
    strTime = request.Form("time")
    strBody = request.Form("body")
    strName = request.Form("name")
    strTel = request.Form("tel")
    strEmail = request.Form("email")

    myArray = Split(Request("time"),",")

    For iy = 0 To UBound(myArray)
    sql = "INSERT INTO appointments (the_Date, the_time, fldSub, fldBod,
    fldName, fldTel, fldEmail) "
    sql = sql & " VALUES
    ('"&strDate&"','"&strTime&"','"&strSubject&"','"&strBody&"','"&strName&"','"
    &strTel&"','"&strEmail&"')"

    set MyConn = oConn.Execute(sql)
    Set MyConn = Nothing
    Next

    but it only inserts into the database the value of the first "time" record
    (e.g. if I selected 00:00, 00:30, 02:30 it inserts "00:00" each of the three
    times through the loop.

    The output of the "time" field is:

    00:00, 00:30, 02:30

    so I thought this line:

    myArray = Split(Request("time"),",")

    would split the "time" field into 3 chunks, and each time through the loop I
    was expecting it to take the next value.

    Am I missing something obvious?

    Thanks

    Jim
    Burton Figg, Jan 18, 2004
    #1
    1. Advertising

  2. Burton Figg

    Ray at Guest

    You're inserting strTime instead of myArray(iy).

    Also, you should split with ", " instead of "," since there's that space in
    between each time value.

    Also, instead of
    Set MyConn = oConn.Execute(sql)
    just use:
    oConn.Execute sql

    One other suggestion I have is to get in the habit of using spaces when
    concatenating strings. Like, instead of:

    &strDate&"','"&strTime&"','"&strSubject&"','"

    do:

    & strDate & "','" & strTime & "','" & strSubject & "','" ...

    In addition to making your code more readable, it'll avoid confusion when
    you're using code like so:

    Dim h1
    h1 = "15 feet"
    Response.Write "Joe jumped "&h1

    Ray at home

    "Burton Figg" <> wrote in message
    news:budel8$ldn$...
    > I have a SELECT statement which holds a list of times (for adding
    > appointments to a database):
    >
    > e.g.
    >
    > <select name="time" id="time" size="3" multiple>
    > <option value="00:00">00:00</option>
    > <option value="00:30">00:30</option>
    > <option value="01:00">01:00</option>
    > <option value="01:30">01:30</option>
    > <option value="02:00">02:00</option>
    > <option value="02:30">02:30</option>
    > </select>
    >
    > on the process page, I want to loop through the values of the "time"

    select
    > field, and enter them into a database.
    >
    > I have tried this:
    >
    > strSubject = request.Form("subject")
    > strDate = request.Form("theDate")
    > strTime = request.Form("time")
    > strBody = request.Form("body")
    > strName = request.Form("name")
    > strTel = request.Form("tel")
    > strEmail = request.Form("email")
    >
    > myArray = Split(Request("time"),",")
    >
    > For iy = 0 To UBound(myArray)
    > sql = "INSERT INTO appointments (the_Date, the_time, fldSub, fldBod,
    > fldName, fldTel, fldEmail) "
    > sql = sql & " VALUES
    >

    ('"&strDate&"','"&strTime&"','"&strSubject&"','"&strBody&"','"&strName&"','"
    > &strTel&"','"&strEmail&"')"
    >
    > set MyConn = oConn.Execute(sql)
    > Set MyConn = Nothing
    > Next
    >
    > but it only inserts into the database the value of the first "time" record
    > (e.g. if I selected 00:00, 00:30, 02:30 it inserts "00:00" each of the

    three
    > times through the loop.
    >
    > The output of the "time" field is:
    >
    > 00:00, 00:30, 02:30
    >
    > so I thought this line:
    >
    > myArray = Split(Request("time"),",")
    >
    > would split the "time" field into 3 chunks, and each time through the loop

    I
    > was expecting it to take the next value.
    >
    > Am I missing something obvious?
    >
    > Thanks
    >
    > Jim
    >
    >
    >
    Ray at, Jan 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NotGiven
    Replies:
    3
    Views:
    333
    Michael D. Kersey
    May 13, 2004
  2. GavMc
    Replies:
    4
    Views:
    314
    Evertjan.
    Sep 22, 2005
  3. Keiron Waites
    Replies:
    1
    Views:
    117
    Keiron Waites
    Oct 21, 2003
  4. palmiere
    Replies:
    1
    Views:
    387
    Erwin Moller
    Feb 9, 2004
  5. Forti2ude
    Replies:
    12
    Views:
    333
    Forti2ude
    Oct 18, 2004
Loading...

Share This Page