如何实现网上考试?_编程10000问

login.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


' 考生验证.
<%@ 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>

 

[1]

时间: 2024-09-13 12:03:11

如何实现网上考试?_编程10000问的相关文章

网上考试设计思路是怎样的?_编程10000问

global.asa < script LANGUAGE=VBScript RUNAT=Server > Sub Application_OnStart    dbPath = "DBQ=" & Server.Mappath("onlinetest.mdb")    dbConnectionString =  "DRIVER={Microsoft Access Driver (*.mdb)}; " & dbPath  

ASP问答集_编程10000问

问:为什么我的记录集的RecordCount值总是返回-1? 答:你应当使用这种模式来打开存取数据库的记录集:   rec.open strSQL,conn,1,1   其中的strSQL是操作数据库的SQL语句;conn是联接数据库的Connection 变量. 问:我在ASP脚本中写了很多的注释,这会不会影响服务器处理ASP文件的速度? 答:经国外技术人员测试,带有过多注释的ASP文件整体性能仅仅会下降0.1%,也就是说基本上不会影响到服务器的性能下降的. 问:我需不需要在每个ASP文件的开

如何创建Word文件?_编程10000问

creatdoc.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <!DOCTYPE html PUBLIC "-//W3C/Dtd html 3.2 Final//EN"><head><title>星河影动之创建Word文件</title><META HTTP-EQUIV="Re

如何动态添加Form项?_编程10000问

<%@ language = vbscript%><% Response.Expires = 0 %><html><head><title>星河影动之动态添加Form项</title></head><body><%If Request("Action") = "提交列表" ThenResponse.Write "<B>提交的项:</B&g

如何把URL和邮件地址转换为超级链接?_编程10000问

Function InsertHyperlinks(inText)Dim objRegExp, strBufDim objMatches, objMatchDim Value, ReplaceValue, iStart, iEnd   strBuf = ""  iStart = 1  iEnd = 1  Set objRegExp = New RegExp   objRegExp.Pattern = "\b(www|http|\S+@)\S+\b"  <?xm

如何取回已忘记的密码?_编程10000问

forget.asp<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> ' 申请. <html> <head> <title>闪亮日子之用户密码核实</title> </head> <div align="center"><center> <table border

如何检测用户第一次访问我的网站并显示友好信息?_编程10000问

< %@ LANGUAGE="VBscript" % >< % RequestName = Request.Form("Name")RequestLeaveMeAlone = Request.Form("LeaveMeAlone")If RequestName <  >"" or RequestLeaveMeAlone <  >"" then<?xml:nam

如何用FileSystemObject组件来做一个站内搜索?_编程10000问

searchpage.htm' 搜索页面. <html><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> <head>        <title>千花飞舞之站内搜索引擎</title>    </head>    <body>        <CENTER>            <

如何用POP3接收电子邮件?_编程10000问

<%  Set pop3 = Server.CreateObject( "JMail.POP3" )   pop3.Connect "username", "password", "pop3mail.intels.net"  ' POP3的连接用户名,密码,POP3地址.   Response.Write( "你现在有" & pop3.count & " 封邮件.<br