Developing an online examination system with ASP

Source: Internet
Author: User
Tags end sql naming convention string split table name variable time limit
Online

The application described in this article is intended for beginners as a reader of ASP programming. Although this example is very simple, it is useful for organizations that try to conduct exams online for their employees, students, or customers.

About this application

The first interface in our application is contained in index.asp, consisting of a registration page with two input fields, one for username and the other for passwords. Non-members must register if they want to take an examination. This page is the initial screen that provides the user with an input box for the user name and password.

It should be noted that the two member domains to be approved should have JavaScript acknowledgments on the client side so that they are not passed as blank fields.
if (TheForm.username.value = "")
{
Alert ("Please enter" "User name\");
TheForm.username.focus ();
return (false);
}
if (TheForm.password.value = "")
{
Alert ("Please enter the" "password\");
TheForm.password.focus ();
return (false);
}

The HTML code to create these fields is as follows:

< table border= "0" cellpadding= "0" >
< tr >
< TD width= "50%" >
< font face= "Verdana" size= "2" >user Name: </font >
</td >
< TD width= "50%" >
< font face= "Verdana" size= "2" >< input Type=text Name=username
size=20 maxlength=50 ></font >
</td >
</tr >
< tr >
< TD width= "50%" >
< font face= "Verdana" size= "2" >password:</font >
</td >
< TD width= "50%" >
< font face= "Vedana" size=2 >< input Type=password Name=password
size=20 maxlength= ></font >
</td >
</tr >
< tr >
< TD width= "100%" colspan= "2" align= "Center" >
< font face= "Verdana" size= "2" >< br > < input type= "submit" value= "Submit" Name= "B3" >
< input type= "reset" value= "reset" name= "B4" >
</font >
</td >
</tr >
</table >
Note that this ASP page is more or less an HTML page, and the reason for ASP pages is to display error messages, such as "bad username or password or select a new username", or any other information that needs to be displayed. The registration form contains some personal information, such as name, Email, password, etc. You can also get information about age, education, occupation, etc. from visitors. Once the personal information is successfully entered, the visitor becomes a member and can use the other parts of the site. Depending on the design requirements of your application, these fields can be either entered or not.

Login Coderegister.asp

This page is displayed when a new visitor registers an online exam. It may require a lot of personal information, but in this case only the name, Email, and password are required. After the form is submitted, the user is led to the sendregister.asp.

Sendregister.asp

Sql_findmember = "SELECT count (*) from loginuser where username =" & username & "
Set rs_findmember = Appl Ication ("Conn"). Execute (sql_findmember)
If rs_findmember (0) < > 0 Then
Session ("message") = "The ENTRY HAD BEEN INSERTED Earli ER.. "Try another log in name"
Response.Redirect "Register.asp"
End If
if Rs_findmember (0) = 0 Then
Sql_inse RT = "INSERT INTO Loginuser (Username,useremail,password) _
Values (" & Username & "," & UserEmail & ", "& pwd &") "
Set Rs_insert = Application (" Conn "). Execute (Sql_insert)
session ("message") = "The ENTRY has BEEN INSERTED ... Thank "
Response.Redirect" "index.asp"
End If

Thus, if Rs_findmember (0) Returns a value of 0, it means that the username does not exist in the database and the name is entered. Members will be able to use other parts of the site. Conversely, if Rs_findmember (0) returns a value greater than 0, the user is booted back to the registered home page and is required to fill out a new username.

Also note that there are some things to be wary of before inserting data into the database. The substitution function is used to ensure that when the visitor types "", you need to replace it.

Username = replace (Request.Form ("Txt_name"), "", "")


Checkuser.asp

At the beginning of the application, after the visitors type their password, their details are pointed to a page, such as sendregister.asp, to verify that the specific username and password exist in the database.
Sql_check = "SELECT count (*) from loginuser where username =" & _
Username & "and password =" & UserEmail & ""
Set Rs_check = Application ("Conn"). Execute (Sql_check)
If Rs_check (0) < > 0 Then
Session ("username") = Request.Form ("username")
Response.Redirect "Default.asp"
End If
If Rs_check (0) = 0 Then
Session ("error") = "wrong USER NAME OR PASSWORD"
Response.Redirect "Index.asp"
End If
The SQL command checks to see if a particular user has been registered. If the return value is 0, the user name or email is invalid, and the user is booted back to the registration page. If it is a member, it is directed to the Default.asp page. This time, the replacement function is used to ensure that if the member has typed ' (single quotes), it will be replaced with (double quotes).
Username = replace (Request.Form ("username"), "", "")
UserEmail = replace (Request.Form ("password"), "", "")

Choose a quiz Default.asp

Once successfully logged in, a second interface appears, providing a list of quiz subjects that members can choose from. In this case, we have HTML and DHTML, and of course we can add tables to increase the number of topics. Default.asp requires that the table be installed with a drop-down menu containing a list of topics. Query the database and collect two fields from the table in the quiz paper.

sql_papers = "Select *id, topic from paper sort order by topic ASC"
SET rs_papers = Application ("Conn"). Execute (Sql_papers)

To display the results in the Drop-down menu, use the following code:

SELECT size=1 name=select1 >
< option value= "0" >select the examination
<%do while not rs_papers. eof% >
< option value= "<%=rs_papers (" id ")% >" ><%=lcase (rs_papers ("topic"))% ></option >
<%
Rs_papers. MoveNext

Loop
% >
The msec function calls redirect.asp on the basis of the X value, and the value of the query string:? x as the value of the selected item in the Drop-down menu.
function msec (x)
{if (x==0)
{Alert ("Please select any one of the examinations")
}
Else
{location. f= "redirect.asp?section=" + X
}
}


Redirect.asp

This page sends the user to the ASP page of the actual generated topics and options. Displays an error message and returns a connection if there are no topics in the database for a specific topic of your choice.
First of all:
id = request.querystring ("section")
Invokes the query string portion and stores the value in the variable ID.
And then:
SQL = "Select Tbl_name from paper where id=" &id
Set RS = Application ("Conn"). Execute (SQL)
Subject= RS (0)
MyString = Split (Subject, "TBL", -1,1)
The SQL declaration passes the domain name table_name in the quiz table. The results are stored in the subject. Further detach the variable subject and store it in the mystring. The Split function is used to display quiz names on the client side to look better.
IF Rs_subject. BOF and Rs_subject. EOF Then
Response.Write Online "& MyString (1) & Test is still to be launched. Come Back _
Later < a href=default.asp >BACK</a > "
Else
Response.Redirect ("exam.asp?section=" &id)
End If
If the above query produces the result, it means that the member chooses the subject which has the question, may carry on the on-line examination. If a particular section is still being created, tell the visitor to come back for the test later. This is the special interest of the examiner, as members can know which of the subjects provided in the previous screen Drop-down menu are pending. Thus, if the section has a title and corresponding options, the page is rebooted to the Exam.asp page, which contains the actual topic.

Quiz code

Exam.asp provides a range of topics and options formatted with radio buttons. In order to make the quiz more challenging, there is a time limit. I set up a clock that starts automatically at mount time, setting it to 20 seconds. The remaining time is displayed in the status window at the bottom of the screen. The time factor can change as well as the number of questions. In order to choose a different topic from the database every time the member wants to take the test, I use a random function. In the database, the number of topics is fixed to 10, each member to answer 5 questions. All the questions are displayed together and then the timer starts. The following code is a function of the timer:
< script language= "JavaScript" >
var ck=0;
var tf=0;
var timeup=0;
var timeleft=0;
var tcount=0;
Timerfunc ();
function Timerfunc () {
Tf=window.settimeout ("Timerfunc ();", 1000);
tcount++;
Timeleft=20-tcount;
Window.status = Timeleft + "Seconds remaining";
}
</script >
Be aware that there is no time limit to the test is not fun.
This page of the query is like this:
id = request.querystring ("section")
Session ("id") = ID
Sql_tblname = "Select Tbl_name from paper where id=" &id
Set rs_tblname = Application ("Conn"). Execute (Sql_tblname)
Subject= rs_tblname (0)
MyString = Split (Subject, "TBL", -1,1)
The query string is stored in a session ("ID"), and the query is started sequentially. The purpose of this SQL declaration is to find the table name from the quiz table. The purpose of using the Split function is to remove TBL from the result. (I used a naming convention that preceded the table name with the TBL prefix). Once the table name is found, the query to the specified table begins. To make the application more interesting, I used random functions to generate any number from 1 to 10. These numbers are used to select an ID from the specified account table:
sql_details = "Select a.ID, A.question, A.choice1, A.choice2,a.choice3," &_
"A.choice4 from" & Subject & "A Where a.id=" &myarray (Counter)
In this query, Id,question, Choice1, Choice2, Choice3, and Choice4 are the domain names in the Account table.
MyArray (Counter) is a random number that has been generated.


After the quiz is finished, the results are stored and added to the database Details table. So members can see the results of the test. (In this case, I only keep one record for the account and a hundred score.) You can also have a time-date flag. )

Record Results result.asp

The main purpose of this page is to display the results and insert the results into the database for future reference.
For each item in Request.Form
Sql_check = "Select Count (*) from" &subject& "where answer =" & Request.Form (item) & ""
Set Rs_check = Application ("Conn"). Execute (Sql_check)
If Rs_check (0) > 0 Then
result = result + 1
End If
Next
The results are stored in the variable result.
Percentages are calculated from result, as follows:
Percent = Round ((* result)/count)
To store this result in a database, execute the following query:
sql_id = "SELECT id from Loginuser where username=" & Session ("username") & ""
Set rs_id = Application ("Conn"). Execute (sql_id)
Id= rs_id (0)
Sql_insert = "INSERT into details (Ref_id,subject,score) VALUES (" & ID & "," _
& Subject & "," & Percent & ")"
Set Rs_insert = Application ("Conn"). Execute (Sql_insert)

View.asp

Watch the module to check if the member has conducted an online exam before. If so, the user is directed to viewrecord.asp. If not, display the appropriate information.
Sql_id= ' select id from loginuser where username= ' & Session ("username") & ""
Set rs_id = Application ("Conn"). Execute (sql_id)
Id= rs_id (0)
Sql_count = "SELECT count (*) from details where ref_id =" & ID & ""
Set Rs_count = Application ("Conn"). Execute (Sql_count)
If rs_count (0) < > 0 Then
Response.Redirect "Viewrecord.asp"
End If
If rs_count (0) = 0 Then
Session ("Noview") = "NO ONLINE examinations HAVE BEEN GIVEN"
Response.Redirect "Default.asp"
End If

Viewrecord.asp

The Viewrecord.asp page allows members to view some of their detail information. The query is as follows:
sql_details = "Select *subject, score from details where ref_id =" & ID & ""

Set rs_details = Application ("Conn"). Execute (Sql_details)
The result is displayed in a simple tabular format.

Please note that I do not limit the number of times a member can conduct a subject to a test. The same subject examination can be carried out at any time.



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.