SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    center pixel
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert checkbox values from dynamic record set

    A page displays the Product literature that a customer can request to receive by postal mail by clicking a check box. The literature selections are created by a dynamic record set based upon what the company enters into the Literature table (currently 10 selections). The checkbox form tags are:

    Code:
    <input type="checkbox" name="LiteratureID" value="<%= rs("LiteratureID")%>">
    LiteratureID is the Access autonumber primary key field. I can use the LiteratureName in the "name" attribute if it is easier.

    The form processing page needs to Insert each selection into its own record in another table. This "requested" table also inserts the database ID for the customer that is created after first inserting the customer contact info. In other words the "requested" table needs to record the customer autonumbered db ID and each selected checkbox value.

    Here is my current code:

    Note: ReqID is the customerID after I inserted the contact info.



    [VBS]For Each record IN request.form("LiteratureID")
    sqlInsert = "INSERT INTO requested (CustomerID, LiteratureID) VALUES"
    sqlInsert = sqlInsert & "(" & ReqID & ","
    sqlInsert = sqlInsert & "" & request.form("LiteratureID") & ");"

    response.write sqlInsert

    NEXT[/VBS]

    Used the response.write sqlInsert to see how it was processing. What happened is that if two checkboxes were selected, the code did not process them as two entries but as one with the values separated by commas, i.e.:

    (39, 3,1) where 39 is the Customer ID and 3 and 1 are the selected check box values.

    Should I be using a loop or array instead?

    Thanks,

    James
    Everything is going as planned...now where is that ball of twine.

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    You'll need to do something like this:

    Code:
    Dim ReqID, strLiteratureID, arrLiteratureID, i
    ReqID           = Request("ReqID")
    strLiteratureID = Request.Form("LiteratureID")
    arrLiteratureID = Split(strLiteratureID, ",")
    
    For i = 0 to UBound(arrLiteratureID)
      strInsert = "INSERT INTO Requested(CustomerID, LiteratureID VALUES" & _
                  "(" & ReqID & ", " & arrLiteratureID(i) & ")"
      my_Conn.Execute (strInsert),,adCmdText + adExecuteNoRecords
    NEXT
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    center pixel
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave,

    Thank you, Thank you, Thank you.

    Worked perfectly.

    James
    Everything is going as planned...now where is that ball of twine.

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Good to hear. Glad I could help.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay so after you've inserted it. Whats the SQL for getting those values out of the field and into an array?

    "Select * from requested.literatureID...."

    I understand how to put checkboxes into an array and place them into a field in the database but how do I get those values out. such that if I want to find all of the users who have signed up for a particular piece of literature.

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2002
    Location
    center pixel
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanmayhew
    Okay so after you've inserted it. Whats the SQL for getting those values out of the field and into an array?

    "Select * from requested.literatureID...."

    I understand how to put checkboxes into an array and place them into a field in the database but how do I get those values out. such that if I want to find all of the users who have signed up for a particular piece of literature.
    Sean,

    It would probably be a join SQL statement that uses the literature ID for the "requested" table and pulls out the customer IDs then gets the customer info from the customer table. I can't think of the SQL join statement off the top of my head.

    Otherwise, another idea is using two recordsets: one that uses the the literature ID to find the customer IDs in the requested table and then use that record set to find the info in the customer table. Hope this helps.

    James
    Everything is going as planned...now where is that ball of twine.


Bookmarks

Posting Permissions

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