I have created a Multi choice Question page in ASP with Submit button.
When I submit my page the User Selected values will be taken to the other page where validation will happen.
My problem is, the number of question will be dynamic and I need to validate the scores and give the final scores.
I tried to use a form collection via for each and validate with my answers but could nt successful
I have tried even writing my selected answers in data base but even that was also not successful .
Can any one know how to validate the answers with database dynamically?
If that’s not possible I want to write the form collections in to data base then validate.
I am attaching my code also.
Expand|Select|Wrap|Line Numbers
- <!--#include file="Reload.asp"-->
- <%
- 'WriteScore= Session("Score")
- usname =Session("name")
- dim chapid
- chapid=11
- Set conn = Server.CreateObject("ADODB.Connection")
- 'Connect to the database
- strMDBpath = Server.MapPath("eLearning.mdb")
- conn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & strMDBPath
- set rs = server.CreateObject ("ADODB.Recordset")
- conn.Close
- Set conn = Nothing
- Set rs = Nothing
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Validate</title>
- </head>
- <body>
- <%
- NOTmyWishArray = array("xpage", "EPQ_Submit")
- for each i in Request.form
- isfound = false
- for j = 0 to Ubound(NOTmyWishArray)
- if lcase(NOTmyWishArray(j)) = lcase(i) then
- isfound = true
- exit for
- end if
- next
- if isfound = false then
- strBody = Request(i)
- 'response.write Request(i)
- 'response.write i
- rs.Open "SELECT * FROM EvaluationTbl where UserName='"& Session("name") &"' AND ChapterID="&chapid&" AND QuestionID="&i&" "), conn, 1
- If rs.recordcount = 0 then
- strSql = "INSERT INTO EvaluationTbl (UserName, ChapterID, QuestionID, UserAnswer) VALUES ('"&Session("name")& "', '"&chapid& "', '"&i&"','"&Request(i)&"')"
- conn.Execute(strSql)
- rs.Close
- conn.close
- set rs=nothing
- Set conn = nothing
- else
- conn.Execute("UPDATE EvaluationTbl SET UserAnswer ='" &Request(i)& "' WHERE ChapterID = " & chapid & " AND UserName = '" & Session("name") & "'AND QuestionID="&i&" ")
- Response.Redirect("eLearning.asp")
- close database
- rs.Close
- conn.close
- set rs=nothing
- Set conn = nothing
- end if
- end if
- next
- %>
- </body>
- </html>