欢迎光临
我们一直在努力

用ASP开发一个在线考试程序(四)

建站超值云服务器,限时71元/月

2000-09-08· 编译青苹果电脑工作室·yesky

checkuser.asp

  在应用程序的开始,访问者键入了他们的口令之后,他们的细节被指向了一页,如sendregister.asp,来检验一下具体

的用户名和口令在数据库中是否存在。

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

  sql命令检查一个特定的用户是否已经注册了。如果返回值为0,就表明用户名或email 无效,将用户引导回注册页。

如果是会员,就被引导到default.asp 页。这一次又用到了替换函数,以保证如果会员键入了‘ (单引号),就要用

(双引号)来替换。

username = replace(request.form("username"),"","")

useremail = replace(request.form("password"),"","")

选择一个测验

default.asp

  一旦成功登录,就出现第二个界面,提供会员可以选择的测验科目的列表。在本例中,我们有html 和dhtml ,当然可

以增加表格以提高主题数。default.asp 要求表格安装一个下拉菜单,其中包含主题的列表。查询数据库,从试卷的表格

中搜集两个域。

sql_papers = "select *id, topic from paper sort order by topic asc"

set rs_papers = application("conn").execute(sql_papers)

  为了在下拉菜单中显示结果,使用以下代码:

select size=1 name=select1 onchange="msec(document.form1._

select1.options[document.form1.select1.selectedindex].value);" >

< 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

% >

  msec函数在x值的基础上调用 redirect.asp,把查询字符串: ?x 的值作为下拉菜单中被选择的项的值。

function msec(x)

{if (x==0)

{ alert("please select any one of the examinations")

}

else

{ location.href="redirect.asp?section=" + x

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用ASP开发一个在线考试程序(四)
分享到: 更多 (0)