为什么conn.execute(up)会使程序返回执行

oasia 2009-08-18 11:17:47
这是一个用户密码修改的页面。
<body>
<%
if request.Form("pwd1")<>"" and request.Form("pwd2")<>"" and request.Form("pwd3")<>"" then
username=cstr(session("username"))
pwd1=filter_Str(request.Form("pwd1"))
pwd2=filter_Str(request.Form("pwd2"))
pwd3=filter_Str(request.Form("pwd3"))

if cint(len(pwd2))<6 or cint(len(pwd2))>12 then
%>
<script language="javascript">
alert("密码必须是6至12位");
window.history.go(-1);
</script>
<%
response.End()
end if
set rs=server.CreateObject("adodb.recordset")
sql=" select * from tb_user where username='"&username&"' and pwd='"&pwd1&"'"
rs.open sql,conn,1,3

if rs.eof or rs.bof then
%>
<script language="javascript">
alert("原密码不正确!");
window.history.go(-1);
</script>
<%
response.End()
else
if pwd2 <> pwd3 then
%>
<script language="javascript">
alert("新密码确认错误");
window.history.go(-1);
</script>
<%
else
up=" update tb_user set pwd='"&pwd2&"' where username='"&username&"'"
conn.execute(up)
%>
<script language="javascript">
alert("密码修改成功,确认后重新登陆");
window.location.href="login.asp";
</script>
<%
response.End()
end if
end if
end if
%>
<div class="sub_main sendmsg_h">
<div class="nav_title">修改密码</div>
<div class=""></div>
<form name="form1" action="" method="post">
<div class="pwd_area">
<ul>
<li class="pwd_li">用户名:
<select name="username" disabled="disabled">
<option value="session("username")"><%=session("username")%></option>
</select>
</li>
<li class="pwd_li">原密码:<input name="pwd1" title="原密码" type="password" class="text1" /></li>
<li class="pwd_li">新密码:<input name="pwd2" title="新密码" type="password" class="text1" /> (6-12位)</li>
<li class="pwd_li">确认新密码:<input name="pwd3" title="确认新密码" type="password" class="text1" /></li>
<li class="pwd_libt"><input name="bt1" type="submit" value="提交" onclick="Mycheck(form1)" class="pwd_bt" /></li>
</ul>

</div>
</form>
</div>
</body>
=========================================================================================
上面程序,当执行完
up=" update tb_user set pwd='"&pwd2&"' where username='"&username&"'"
conn.execute(up)
后,紧跟着的js弹窗("密码修改成功,确认后重新登陆");竟然不会弹出,而是弹出最上面的“原密码不正确”窗口,打开数据库,密码是已经被修改了。为什么程序会返回最上面呢?
我试过把response.end()放在conn.execute(up)后,程序依然会返回弹出最上面的“原密码不正确”窗口。密码也已经成功修改。
最后我把conn.execute(up)这句去掉,"密码修改成功,确认后重新登陆"的弹窗可以出来了,程序也不会返回最前面。这样就证实了是conn.execute(up)这句的问题。不知道怎么解决。

%>
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sy_binbin 2009-08-18
  • 打赏
  • 举报
回复
<body>
<%
if request.Form("pwd1") <>"" and request.Form("pwd2") <>"" and request.Form("pwd3") <>"" then
username=cstr(session("username"))
pwd1=filter_Str(request.Form("pwd1"))
pwd2=filter_Str(request.Form("pwd2"))
pwd3=filter_Str(request.Form("pwd3"))

if cint(len(pwd2)) <6 or cint(len(pwd2))>12 then
%>
<script language="javascript">
alert("密码必须是6至12位");
window.history.go(-1);
</script>
<%
response.End()
end if
set rs=server.CreateObject("adodb.recordset")
sql=" select * from tb_user where username='"&username&"' and pwd='"&pwd1&"'"
rs.open sql,conn,1,3

if rs.eof and rs.bof then
%>
<script language="javascript">
alert("原密码不正确!");
window.history.go(-1);
</script>
<%
response.End()
else
if pwd2 <> pwd3 then
%>
<script language="javascript">
alert("新密码确认错误");
window.history.go(-1);
</script>
<%
else
up=" update tb_user set pwd='"&pwd2&"' where username='"&username&"'"
conn.execute(up)
%>
<script language="javascript">
alert("密码修改成功,确认后重新登陆");
window.location.href="login.asp";
</script>
<%
response.End()
end if
end if
end if
%>
<div class="sub_main sendmsg_h">
<div class="nav_title">修改密码 </div>
<div class=""> </div>
<form name="form1" action="" method="post">
<div class="pwd_area">
<ul>
<li class="pwd_li">用户名:
<select name="username" disabled="disabled">
<option value="session("username")"> <%=session("username")%> </option>
</select>
</li>
<li class="pwd_li">原密码: <input name="pwd1" title="原密码" type="password" class="text1" /> </li>
<li class="pwd_li">新密码: <input name="pwd2" title="新密码" type="password" class="text1" /> (6-12位) </li>
<li class="pwd_li">确认新密码: <input name="pwd3" title="确认新密码" type="password" class="text1" /> </li>
<li class="pwd_libt"> <input name="bt1" type="submit" value="提交" onclick="Mycheck(form1)" class="pwd_bt" /> </li>
</ul>

</div>
</form>
</div>
</body>
sy_binbin 2009-08-18
  • 打赏
  • 举报
回复
if rs.eof and rs.bof then
lh57 2009-08-18
  • 打赏
  • 举报
回复
<body>
<%
if not isempty(request.form("bt1")) then
if request.Form("pwd1") <>"" and request.Form("pwd2") <>"" and request.Form("pwd3") <>"" then
username=cstr(session("username"))
pwd1=filter_Str(request.Form("pwd1"))
pwd2=filter_Str(request.Form("pwd2"))
pwd3=filter_Str(request.Form("pwd3"))

if cint(len(pwd2)) <6 or cint(len(pwd2))>12 then
%>
<script language="javascript">
alert("密码必须是6至12位");
window.history.go(-1);
</script>
<%
response.End()
end if
set rs=server.CreateObject("adodb.recordset")
sql=" select * from tb_user where username='"&username&"' and pwd='"&pwd1&"'"
rs.open sql,conn,1,3

if rs.eof or rs.bof then
%>
<script language="javascript">
alert("原密码不正确!");
window.history.go(-1);
</script>
<%
response.End()
else
if pwd2 <> pwd3 then
%>
<script language="javascript">
alert("新密码确认错误");
window.history.go(-1);
</script>
<%
else
up=" update tb_user set pwd='"&pwd2&"' where username='"&username&"'"
conn.execute(up)
%>
<script language="javascript">
alert("密码修改成功,确认后重新登陆");
window.location.href="login.asp";
</script>
<%
response.End()
end if
end if
end if
end if
%>
<div class="sub_main sendmsg_h">
<div class="nav_title">修改密码 </div>
<div class=""> </div>
<form name="form1" action="" method="post">
<div class="pwd_area">
<ul>
<li class="pwd_li">用户名:
<select name="username" disabled="disabled">
<option value="session("username")"> <%=session("username")%> </option>
</select>
</li>
<li class="pwd_li">原密码: <input name="pwd1" title="原密码" type="password" class="text1" /> </li>
<li class="pwd_li">新密码: <input name="pwd2" title="新密码" type="password" class="text1" /> (6-12位) </li>
<li class="pwd_li">确认新密码: <input name="pwd3" title="确认新密码" type="password" class="text1" /> </li>
<li class="pwd_libt"> <input name="bt1" type="submit" value="提交" onclick="Mycheck(form1)" class="pwd_bt" /> </li>
</ul>

</div>
</form>
</div>
</body>
oasia 2009-08-18
  • 打赏
  • 举报
回复
跟and or 没关系,就算换了也是一样

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧