注册 登录
编程论坛 ASP技术论坛

后台登陆验证

青年求知 发布于 2008-11-14 17:40, 1511 次点击
<%
dim username
dim password
 username=request.form("myuser")
 password=request.form("mypassword")
 set rs=server.createobject("adodb.recordset")
 sql="select * from users where u_user='"&username&"'"
 rs.open sql,conn,1,1
 if rs.eof then
  response.write "<script>alert('登录失败');history.back();</script>"
  response.end
  else
    if rs("u_password")<>"password" then
      response.write "<script>alert('登录失败');history.back();</script>"
      response.end     
     end if      
     session("admin")="username"
response.write"<script>alert('登录成功');location.href='index.asp'</script>"
  end if
%>


请问以上的代码哪里出错了吗? 为什么每次运行的时候都是弹出"登录失败" .知道的高手请指点我一下,谢谢了.
8 回复
#2
hmhz2008-11-14 17:52
if rs("u_password")<>password then

session("admin")=username

注意双引号,在asp里,双引号之间的不是变量,而是值
#3
214112008-11-15 12:41
试下这样行不行?
<%
dim username
dim password
username=trim(request.form("myuser"))
password=trim(request.form("mypassword"))
set rs=server.createobject("adodb.recordset")
sql="select * from users where u_user='"&username&"' and u_password='"&password&"'"
rs.open sql,conn,1,1
if rs.eof then
  response.write "<script>alert('登录失败');history.back();</script>"
  response.end
  else     
     session("admin")="username"
response.write"<script>alert('登录成功');location.href='index.asp'</script>"
  end if
%>
#4
青年求知2008-11-15 18:11
谢谢大家了.可 还是不行啊.
#5
hokers2008-11-15 18:20
if rs("u_password")<>"password" then
      response.write "<script>alert('登录失败');history.back();</script>"
      response.end     
 else
     session("admin")="username"
     response.write"<script>alert('登录成功');location.href='index.asp'</script>"
  end if     
end if
#6
multiple19022008-11-15 18:46
rs里面的password到底应该跟谁比较?
#7
Roxy2008-11-15 20:06
我也有过这问题
我在刚开始学写代码的时候也出过一次,也不知道怎么的老是弄不好
#8
coffecat11192008-11-16 09:09
你代码里的单引号是不是在中文状态下输入的啊?
你代码里的单引号是不是在中文状态下输入的啊?
#9
青年求知2008-11-27 21:50
谢谢大家了。我已经把问题解决了。
1