Code Analysis of ASP Online examination system

Source: Internet
Author: User
Tags generator min reset trim access database visual studio
Online Exams

With the development of Internet technology, online teaching will become the main form for people to receive re-education and lifelong education. In online schools, people can choose to learn any course anywhere, anytime and anywhere, without the restriction of time and space. The development of the online school has put forward the urgent request to the development of the online examination. Here is an online exam system that I implemented using ASP and Access database. When the user login by user name and password, the system first check whether the user has participated in the examination, if the results of the query, if otherwise, from the question bank to extract the questions for the user to answer. After the user submits the answer sheet, the system scores and registers the results.

one. Database Design

First set up a database Exercise.mdb, which includes two tables: the user and Test,user tables include three fields:

Field name: User; field type: text; Field Size: 20. Store User Name

Field name: passwd; field type: text; Field Size: 20. Store user Password

Field name: Score; field type: number; Field size: integral type. Store user Scores
There are five fields in the test table:
Field name: Question; field type: text; Field Size: 255. Storing test questions

Field name: A; field type: text; field Size: 100. Answer to storage option A

Field name: b; field type: text; field Size: 100. The answer to storage option B

Field name: C; field type: text; field Size: 100. The answer to storage option C

Field Name: D; field type: text; field Size: 100. Storage Option D Answer

Field name: ans; field type: text; Field Size: 2. Store correct answers

two. Program Original Code
  
The following is the core of the system in the three section of the original program, hope that the development of similar systems readers to get the role of the reader can also be improved to adapt to their own system.

The following are the referenced contents:
' Login.asp source program to verify the legality of the user
<%@ language=vbscript% >
<%
Name=trim (Request ("name"))
Passwd=trim (Request ("passwd"))
' Check if the user enters information
If name< > "" and passwd< > "" Then
Set conn = Server.CreateObject
("ADODB.") Connection ")
Conn. Open Driver={microsoft Access
Driver (*.mdb)};d bq= "&
Server.MapPath ("Exercise.mdb")
Set rs= Server.CreateObject ("Adodb.recordset")
Sql= "SELECT * from user where user= '" &name&
"' and Passwd= '" & passwd & "'"
' Check the legality of the user
Set rs= Conn. Execute (SQL)
If not (rs.eof) then
Check if the user has taken the exam,
If you have a performance check
If RS ("score") < >0 Then
Response.Write rs ("user") &
"The test score is" &rs ("score")
Else
Session ("Pass") =1
Session ("User") =name
Response.Redirect "Test.asp"
End If
Else
Response.Write "I'm sorry,
The user or password is incorrect!!! "
End If
Else
End If
% >
< HTML >
< head >
< META name= "generator"
Content= "Microsoft Visual Studio 6.0" >
< TITLE > User password check </title >
< BODY >
< FORM action= "Login.asp" Id=form1
Method=post Name=form1 >
< P title= "" > </p >
< P title= "" > </p >
< P title= "" Align=center > User:
< INPUT Id=text1 Name=name
Style= "HEIGHT:22PX; width:103px "></p >
< P title= "" Align=center > Password:
< INPUT id=password1 NAME=PASSWD
Style= "HEIGHT:23PX; Width:101px "
Type=password ></p >
< P title= "" Align=center >
< INPUT id=submit1 Name=submit1
Type=submit value= "into the style=" Font-size:
Medium Font-style:normal;
Font-variant:normal; Font-weight:
Bold "title=" ></p >
< P title= "" Align=center >
</p >
</form >
</body >

' test.asp source program, extract the questions from the question bank to answer
<%@ language=vbscript% >
<%
If session ("Pass") < >1 Then
Response.Redirect "Login.asp"
Else
End If
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open Driver={microsoft Access Driver
(*.mdb)}; Dbq= "&
Server.MapPath ("Exercise.mdb")
' Extract the questions
Sql= "SELECT * FROM Test"
Set RS = conn. Execute (SQL)
% >
' Timer function
< SCRIPT language= "JavaScript" >
var isn1=null;
var Isn2=false;
Today=new Date ();

function StoPit () {
if (ISN2) {
Cleartimeout (ISN1);
}
ISN2 = false;
}
function Startit () {
StoPit ();
Isnclock ();
}

function Isnclock () {
var now=new Date ();
var hrs=now.gethours ();
var min=now.getminutes ();
var sec=now.getseconds ();
Document.clckh.disp.value= "" + (hrs >12)?
hrs-12:hrs);
Document.clckm.disp.value= ((min< 10)? "0": "") +min;
Document.clcks.disp.value= ((sec< 10)? "0": "") +sec;
document.clck.disp.value= (hrs >=12)? "p.m.": "A.M";
Isn1=settimeout ("Isnclock ()", 1000);
Isn2=true;
}
</script >

< HTML >
< head >
< META name= "generator"
Content= "Microsoft Visual Studio 6.0" >
< body bgcolor= "FFFFFF" >
< Center >
' Call the timer function to show the time
< TABLE border=2 >
< TR >
< TD >Time</TD >< TD >Hour</TD >< TD >min
</td >< TD >Sec</td >< TD ></td >
</tr >
< TR >
< TD ></td >
< TD valign=top >< FORM name= "Clckh" >
< INPUT type= "text" name= "disp" size=2 VALUE = "" >
</form ></td >
< TD valign=top >< FORM name= "clckm" >
< INPUT type= "text" name= "disp" size=2 VALUE = "" >
</form ></td >
< TD valign=top >< FORM name= "Clcks" >
< INPUT type= "text" name= "disp" size=2 VALUE = "" >
</form ></td >
< TD valign=top >< FORM name= "Clck"
>
< INPUT type= "text" name= "disp" size=4 VALUE = "" >
</form ></td ></tr >
</center >
' Show questions for answers
< FORM action= "result.asp" Id=form1
Method=post Name=form1 >
< P > </p >
< P >
<%
I=1
Rs.movefirst
Do, not rs.eof% >
< P > <%=rs ("question")% ></p >
< TABLE align=center Border=1 cellpadding=1
Cellspacing=1
Width= "80%" >
< TR >
< TD style= "width:50%" width= "50%"
< INPUT name=ans<%=i% > Type=radio value= "A" >
<%=rs ("a")% ></td >
< TD >< INPUT name=ans<%=i% >
Type=radio value= "B" >
<%=rs ("B")% ></td ></tr >
< TR >
< TD >< INPUT name=ans<%=i% >
Type=radio value= "C" >
<%=rs ("C")% ></td >
< TD >< INPUT name=ans<%=i% >
Type=radio value= "D" >
<%=rs ("D")% ></td >
</tr >
</table >
<%
I=i+1
Rs.movenext
Loop
% >
</p >
< P > </p >
< P align=center >< INPUT id=submit1 name=submit1
Type=submit
Value=submit >< INPUT Id=reset1 Name=reset1
Type=reset value=reset ></P ></form >
</body >

The following are the referenced contents:
' result.asp source program, scoring on user responses,
And record the scores in the storage
<%@ language=vbscript% >
< HTML >
< head >
< META name= "generator" content= "Microsoft
Visual Studio 6.0 ">
< BODY >
< P > </p >
<%
Name=session ("User")
Dim score
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "driver=
{Microsoft Access Driver (*.mdb)};d bq= "
& Server.MapPath ("Exercise.mdb")
Sql= "Select ans from Test"
Set RS = conn. Execute (SQL)
Ycorrect=0
Rscount=0
' Give the correct answer and score
Response.Write "Correct answer:"
Do as not rs.eof
Response.Write Rs ("ans")
Rscount=rscount+1
If Request.Form (rscount) =rs ("ans") Then
Ycorrect=ycorrect+1
End If
Rs.movenext
Loop
Response.Write "< br > Your answer:"
Score=int (ycorrect/rscount*100)
For I=1 to Request.form.count-1
Response.Write Request.Form (i)
Next
Response.Write "< br >"
Response.Write "Your grades:" &score
If score< then Response.Write "You fail!" "&" < br > "
else if score >=60 Response.Write "Pass" & "< br >"
Else Response.Write "Excellent!" "
' Register the results in the library
Strsql= "INSERT into user [result] values (" &score& ")
where user= ' "&name&" "
Conn.execute (strSQL)
% >
</body >



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.