标题:記錄集合
只看楼主
rgbtdkjcel
Rank: 1
等 级:新手上路
帖 子:294
专家分:0
注 册:2007-3-26
结帖率:50%
 问题点数:0 回复次数:2 
記錄集合
Do While Not rs.eof
         If (username=rs("name") And userpassword=rs("pwd")) Then
            If (username="admin") Then
              session("admin")="admin"
              session("username")=username
              response.redirect "manager.asp"
              Else
                session("status")="ok"
                session("username")=username
                response.redirect "main.asp"
             End If
            Else
             response.write "aa"
             End If
           rs.movenext
              loop

當if語句為假時。為何response.write "aa"執行的次數是數據庫中的記錄條數呢?我想只輸出一次該如何處理!!!謝謝
搜索更多相关主题的帖子: username response session admin 
2007-12-17 16:56
tianyu123
Rank: 1
等 级:新手上路
威 望:2
帖 子:576
专家分:0
注 册:2007-8-26
得分:0 
你使用了 do while ... loop 当然会遍历数据库中的所有记录
<%
username=request.form("username")
userpassword=request.form("userpassword")
set rs=server.createobject("adodb.recordset")
sql="select name,pwd from 用户表 where name=' "& username & "'"
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
   if username=rs("name") and userpassword=rs("pwd") then
      If (username="admin") Then
          session("admin")="admin"
          session("username")=username
          response.redirect "manager.asp"
       else
          session("status")="ok"
          session("username")=username
           response.redirect "main.asp"
       end if
   else
     response.write"<script>alert('密码错误!');history.go(-1);</script>"
   end if
else
   response.write"<script>alert('用户名错误!');history.go(-1);</script>"
   rs.close
   set rs=nothing
   conn.close
   set conn=nothing
   response.end
end if
%>

改变一切,须从改变观念开始!
2007-12-17 17:19
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
Do While Not rs.eof
         If (username=rs("name") And userpassword=rs("pwd")) Then
            If (username="admin") Then
              session("admin")="admin"
              session("username")=username
              response.redirect "manager.asp"
              Else
                session("status")="ok"
                session("username")=username
                response.redirect "main.asp"
             End If
            Else
             response.write "aa"
             End If
           rs.movenext
              loop
证明记录集中没有符合(username=rs("name") And userpassword=rs("pwd"))
这个条件的记录集,察看变量是否有值。
2007-12-17 17:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-192978-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.098924 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved