ASP程序中的问题(求教)

来源:百度知道 编辑:UC知道 时间:2024/06/14 09:32:59
<!--#include file="conn.asp"-->
<%
exec="select admin from yhbd"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,3,2
%>
<%
dim a,b
a=request.Form("b1") '这里的b1=表单里的用户名
b=request.Form("b2") '这里的b2=表单里的密码
if a="" or b="" then
response.Write"<script language=javascript>alert('用户名与密码不能为空');window.location.href='index.asp';</script>"
else
if a=rs("admin") and b=rs("password") '主要问题在这里,如何判断a和b的值是否与数据库里的值相同,我这样写好像不正确,能否指点下
response.Write"<script language=javascript>alert('OK');window.location.href='index.asp';</script>"
else
rs.close
set rs=nothing
end if
end if
%>
说明下:数据库字段名分别是admin和password 都是文本类型

数据库是用的 ACCESS

下面的朋友 谢谢你 我是要解决当前的问题! 不需要你给我一段那么长的代码!辛苦了

把你的代码改了一下,做了注释

<!--#include file="conn.asp"-->
<%
dim a,b
a=request.Form("b1")
b=request.Form("b2")
if a="" or b="" then
response.Write"<script language=javascript>alert('用户名与密码不能为空');window.location.href='index.asp';</script>"
else
'判断输入的用户名是否存在
exec="select * from yhbd where admin='"&a&"'"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,3,2
if not rs.eof then
'如果用户名存在,再判断密码是否正确
if b=rs("password") then
response.Write"<script language=javascript>alert('OK');window.location.href='index.asp';</script>"
else
response.Write("密码错误")
end if
else
response.Write("用户名不存在")
end if
end if
%>

没有必要这样写哈 你将相应用