checkboxes and other form inserts into a database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrHelpMe

    checkboxes and other form inserts into a database

    Hello experts,

    I need a hand. On my asp submit page I have the following code:
    Code:
    for i = 1 to 5 ' 5 question form'
    
    Question = Request.Form("Q" & i)
    Answer = Request.Form("A" & i)
    Comment  = Request.Form("C" & i )
    
    ValComment = Replace(Comment, "'", "''")
    ValAnswer = Replace(Answer, "'", "''")
    
    checkbox = Request.Form("check")
    checkbox = Split(checkbox,", ")
    -----------------------------------------------------------------------------------------
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "removed for security reasons"
    set sSQL = server.CreateObject ("ADODB.Recordset")
    set sSQL1 = server.CreateObject ("ADODB.Recordset")
    --------------------------------------------------------------------------------------------
    IF........somthing here in the checkbox = STRUGGLING HERE please help
    sSQL = "INSERT into Table (ID, Question, Answer, Comments, TimeStamp,
    UserID)"
    sSQL = sSQL &  "VALUES (Test_seq.nextval, '" & Question &"', '" &
    checkbox &"', '" & ValComment &"', sysdate, '"& User & "')"
    
    Else
    sSQL1 = "INSERT into table (ID, Question, Answer, Comments, TimeStamp,
    UserID)"
    sSQL1 = sSQL1 &  "VALUES (Test_seq.nextval, '" & Question &"', '" &
    ValAnswer &"', '" & ValComment &"', sysdate, '"& User & "')"
    response.write ssql1 & "<BR>"
    End IF
    Next
    response.end
    Note: just the bulk of the code has been added so that you get an idea
    of what it is that I am talking about.

    On my html form I have a combination of dropdownlists and combo
    boxes. The checkboxes all have the same name. It is basically 1
    question checkbox with the ability to choose 5 answers. I have a
    total of 5 questions(1 checkbox question and 3 drop downs and 1
    textbox. What I am struggling with is how do I get the answers from
    the checkboxes into the database as well as the other form elements.
    If it is much easier to not parse the comma separated list then so be
    it:) Thanks everyone.

  • ThatsIT.net.au

    #2
    Re: checkboxes and other form inserts into a database


    "MrHelpMe" <clinttoris@hot mail.comwrote in message
    news:1175003671 .355252.129860@ n59g2000hsh.goo glegroups.com.. .
    Hello experts,
    >
    I need a hand. On my asp submit page I have the following code:
    Code:
    >
    for i = 1 to 5 ' 5 question form'
    >
    Question = Request.Form("Q" & i)
    Answer = Request.Form("A" & i)
    Comment  = Request.Form("C" & i )
    >
    ValComment = Replace(Comment, "'", "''")
    ValAnswer = Replace(Answer, "'", "''")
    >
    checkbox = Request.Form("check")
    checkbox = Split(checkbox,", ")
    -----------------------------------------------------------------------------------------
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "removed for security reasons"
    set sSQL = server.CreateObject ("ADODB.Recordset")
    set sSQL1 = server.CreateObject ("ADODB.Recordset")
    --------------------------------------------------------------------------------------------
    IF........somthing here in the checkbox = STRUGGLING HERE please help
    Code:
    if checkbox(0) = correct answer then
    
    [QUOTE]
    sSQL = "INSERT into Table (ID, Question, Answer, Comments, TimeStamp,
    UserID)"
    sSQL = sSQL &  "VALUES (Test_seq.nextval, '" & Question &"', '" &
    checkbox &"', '" & ValComment &"', sysdate, '"& User & "')"[/QUOTE]
    
    you have set sSQL to be a recordset. now you are treating it as a string.
    
    
    a recordset is for reading from a database, not for writting to it.
    
    you need somthing like this
    
    sql = "your sql statement"
    
    cn.open "your connection string"
    cn.execute(sql)
    cn.close
    
    
    
    
    [QUOTE]
    >
    Else
    sSQL1 = "INSERT into table (ID, Question, Answer, Comments, TimeStamp,
    UserID)"
    sSQL1 = sSQL1 &  "VALUES (Test_seq.nextval, '" & Question &"', '" &
    ValAnswer &"', '" & ValComment &"', sysdate, '"& User & "')"
    response.write ssql1 & "<BR>"
    End IF
    Next
    response.end
    [/QUOTE]
    >
    Note: just the bulk of the code has been added so that you get an idea
    of what it is that I am talking about.
    >
    On my html form I have a combination of dropdownlists and combo
    boxes. The checkboxes all have the same name. It is basically 1
    question checkbox with the ability to choose 5 answers. I have a
    total of 5 questions(1 checkbox question and 3 drop downs and 1
    textbox. What I am struggling with is how do I get the answers from
    the checkboxes into the database as well as the other form elements.
    If it is much easier to not parse the comma separated list then so be
    it:) Thanks everyone.
    >

    Comment

    Working...