checkboxes and other form inserts into a database

checkboxes and other form inserts into a database

am 27.03.2007 15:54:31 von clinttoris

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 & "
"
End IF
Next
response.end
[/code]

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.

Re: checkboxes and other form inserts into a database

am 04.04.2007 18:21:02 von me

"MrHelpMe" wrote in message
news:1175003671.355252.129860@n59g2000hsh.googlegroups.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

if checkbox(0) = correct answer then


> sSQL = "INSERT into Table (ID, Question, Answer, Comments, TimeStamp,
> UserID)"
> sSQL = sSQL & "VALUES (Test_seq.nextval, '" & Question &"', '" &
> checkbox &"', '" & ValComment &"', sysdate, '"& User & "')"

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





>
> 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 & "
"
> End IF
> Next
> response.end
> [/code]
>
> 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.
>