下面就是满足你设想的几个主程序,你还可以在实际应用中不断完善和扩充:
login.asp
考生验证
<%@ language=vbscript%>
<%
name=trim(request("name"))
passwd=trim(request("passwd"))
if name<>"" and passwd<>"" then
检查考生是否输入用户名和密码
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft access driver(*.mdb)};
dbq="& server.mappat("exercise.mdb")
set rs= server.createobject("adodb.recordset")
sql= "select * from user where user=
" &name&" and passwd=" & passwd &""
set rs= conn.execute(sql)
验证考生合法性
if not(rs.eof) then
if rs("score")<>0 then
检查考生是否已参加过考试,若是则进行成绩查询
response.write rs("user")&"的考试成绩是"&rs("score")
else
session("pass")=1
session("user")=name
response.redirect "test.asp"
end if
else
response.write "噢,您输入的用户名或密码不正确!"
end if
else
end if
%>
<html>
<head>
<meta name="generator" content="microsoft visual studio 6.0">
<title>精彩春风之考生登录</title>
</head>
<body>
<form action="login.asp" id=
form1 method=post name=form1>
<p title="">&nbsp;</p>
<p title="">&nbsp;</p>
<p title="" align=center>考生:
<input id=text1 name=name style="height:22px; width: 103px"></p>
<p title="" align=center>密码:
<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="进入 " style="font-size: medium; font-style: normal; font-variant:normal; font-weight: bold" title=""></p>
<p title="" align=center>
</p>
</form>
</body>
</html>
test.asp
从题库中取题考试
<%@ 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")
sql="select * from test"
set rs = conn.execute( sql )
提取试题
%>
<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">
</head>
<body onload="startit()" bgcolor="ffffff">
<center>
调用计时函数显示时间
<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" onsubmit="0">
<input type="text" name="disp" size=2 value ="">
</form></td>
<td valign=top><form name="clckm" onsubmit="0">
<input type="text" name="disp" size=2 value ="">
</form></td>
<td valign=top><form name="clcks" onsubmit="0">
<input type="text" name="disp" size=2 value ="">
</form></td>
<td valign=top><form name="clck" onsubmit="0">
<input type="text" name="disp" size=4 value ="">
</form></td></tr>
</center>
<form action="result.asp" id=form1 method=post name=form1>
显示试题
<p>&nbsp;</p>
<p>
<%
i=1
rs.movefirst
do while not rs.eof%>
<p>&nbsp;&nbsp; <%=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=交卷>
<input id=reset1 name=reset1 type=reset value=reset></p></form>
</body>
</html>
result.asp
评分并将成绩记录到数据库
<%@ language=vbscript %>
<html>
<head>
<meta name="generator" content="microsoft visual studio 6.0">
</head>
<body>
<p>&nbsp;</p>
<%
name=session("user")
dim score
set conn = server.createobject("adodb.connection")
conn.open "driver={microsoft access driver(*.mdb)};
dbq=" & server.mappath("exercise.mdb")
sql="select ans from test"
set rs = conn.execute( sql )
ycorrect=0
rscount=0
response.write "标准答案:"
给出标准答案并评分
do while 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>您的答案:"
score=int(ycorrect/rscount*100)
for i=1 to request.form.count-1
response.write request.form(i)
next
response.write "<br>"
response.write "您的成绩:"&score
if score<60 then response.write "别难过,您不及格!"&"<br>"
else if score>=60 response.write "幸好,您及格了!"&"<br>"
else response.write "恭喜,您获得了优秀!"
strsql="insert into user (result) values ("&score&")
where user="&name&""
conn.execute(strsql)
将成绩存到数据库
%>
</body>
</html>
exercise.mdb数据库,包含两个表:user 和test:
user表:
序号 字段名称 字段类型 字段大小 作 用
1 user 文本 20 考生名
2 passwd 文本 20 考生密码
3 score 数字 整型 考生成绩
test表:
序号 字段名称 字段类型 字段大小 作 用
1 question 文本 255 考试题目
2 a 文本 100 选项a答案
3 b 文本 100 选项b答案
4 c 文本 100 选项c答案
5 d 文本 100 选项d答案
6 ans 文本 2 标准答案