PDA

View Full Version : marking the users in the online test


pinkcat_02
04-11-2003, 04:32 PM
I am trying to design an online test in ASP. I have 2 different kind of questions

1.there is radio button ones where the user selects the correct answer
2.there is text box where the user types in the correct answer.

The questions are selected randomly from the database. 5 questions are displayed each time the user takes a test. In my database I have a table for questions and another table for Answers.

To make it easier each questions <name> tag is the question itself.

Now I have managed to display the questions and for marking them I am first inserting the user answers to the database. I have written the code but keeps giving sytanx error at this point:

if Request.Form("Question") <> <% RS.Question("Ans") %> then


I am posting the whole code I am confused at some parts of the code myself but someone may have an idea.

Thanks.

<%@ Language = "VBScript"%>
<%
dim conn
dim strSQL
dim strSQL2
dim strAns1
dim strAns2
dim strAns3
dim strAns4
dim strAns5

strAns1 = Request.Form("Question")
strAns2 = Request.Form("Question")
strAns3 = Request.Form("Question")
strAns4 = Request.Form("Question")
strAns5 = Request.Form("Question")



Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\db\dbs.mdb"))

strSQL2 = "INSERT INTO Answer (Ans1, Ans2, Ans3, Ans4, Ans5 ) Values ('" & Question & "','" & Question & "','" & Question & "','" & Question & "','" & Question & "')"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open strSQL2, conn, 3, 3



if Request.Form("Question") <> <% RS.Question("Ans") %> then
Session("Wrong")="T"
Session("Errors")=Session("Errors") + 1
end if
if Session ("Errors") > 0 then
response.write "Correct answers: " & Session (Errors) & "

else

Response.Write "Well done! All you have answered all questions correctly. "
end if
%>

Roy Sinclair
04-11-2003, 04:46 PM
Of course this code gives a syntax error:

if Request.Form("Question") <> <% RS.Question("Ans") %> then

You're already in VBScript at this point so the additional <% %> tags are simply wrong and cause errors.

Try:

if Request.Form("Question") <> RS.Question("Ans") then