checkboxes and other form inserts into a database

Discussion in 'ASP General' started by MrHelpMe, Mar 27, 2007.

  1. MrHelpMe

    MrHelpMe Guest

    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.
     
    MrHelpMe, Mar 27, 2007
    #1
    1. Advertising

  2. "MrHelpMe" <> wrote in message
    news:...
    > 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[/color]
    
    if checkbox(0) = correct answer then
    
    [color=blue]
    > sSQL = "INSERT into Table (ID, Question, Answer, Comments, TimeStamp,
    > UserID)"
    > sSQL = sSQL &  "VALUES (Test_seq.nextval, '" & Question &"', '" &
    > checkbox &"', '" & ValComment &"', sysdate, '"& User & "')"[/color]
    
    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
    
    
    
    
    [color=blue]
    >
    > 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, Apr 4, 2007
    #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. michi
    Replies:
    0
    Views:
    342
    michi
    Oct 27, 2004
  2. Marcus Leon
    Replies:
    2
    Views:
    329
    shakah
    Jun 7, 2005
  3. Replies:
    2
    Views:
    457
  4. Fendi Baba
    Replies:
    1
    Views:
    512
    Alvin Bruney [MVP]
    Feb 11, 2007
  5. Margaret Smith
    Replies:
    3
    Views:
    153
    Raveendran Perumalsamy
    Jul 16, 2009
Loading...

Share This Page