急等。请问这段asp登录的代码哪里错了

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:44:59
if Request.ServerVariables ("REQUEST_METHOD")="POST" then
dim username,password
username=trim(Request.Form ("username"))
password=trim(Request.Form ("password"))
if username<>""and password<>""then
set rs=server.CreateObject("adodb.recordset")
sql="select username,password from admin where username='" & username & "' and password='" & password & "'"
rs.open sql,conn,1,1
if username=rs("username") and password=rs("password") then
session("login")="ok"
response.redirct("news.asp")
else
response.write ("用户名或密码输入错误,请确认!<a href='index.asp'>重新登录</a>")
end if
else
response.write ("用户名或密码不能为空,请确认!<a href='index.asp'>重新登录</a>")
end if
rs.close
se

这么改,用这种方法比较好!

sql="select count(*) as countuser from admin where username='" & username & "' and password='" & password & "'"

If Rs("countuser") >= 1 Then
Response.write "登陆成功"
Else
Response.write "登陆失败"
End If

用你那种方法可能查不出记录所以直接rs("username")这个就会出错,要用你那个可以是用If Rs.Eof Then 来判断有无记录!