[求助]下面的脚本执行完if又执行else
代码为修改密码的脚本
先判断旧密码是否正确,如果正确就update新密码,否则提示旧密码不正确,
在执行的时候脚本有时正确,有时在旧密码正确时update了新密码,同时又执行了else里的alert("旧密码输入错误,请重新输入!^_^");
不知有没有哪位知道是何原因!
代码如下
<%!
public String code(String s)
{ String str=s;
try{byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e) {return str;}
}
%>
<%
String oper_id=code((String)session.getAttribute("oper_id"));
String oper_pwd=code((String)session.getAttribute("oper_pwd"));
String npwd=code(request.getParameter("newpwd1"));
String npwd2=code(request.getParameter("newpwd2"));
String opwd=code(request.getParameter("oldpwd"));
Connection con2;
Statement sql2;
ResultSet rs2;
String sqlstr2="select * from bb_operator where is_valid=1 and oper_id='"+oper_id+"' and password='"+opwd+"' ";
try{Class.forName(DB_DRIVER);
}
catch(ClassNotFoundException e) {}
try {
con2=DriverManager.getConnection(CONNSTRING,DB_USERNAME,DB_PASSWORD);
sql2=con2.createStatement();
rs2=sql2.executeQuery(sqlstr2);
if(rs2.isBeforeFirst())
{
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName(DB_DRIVER);
}
catch(ClassNotFoundException e) {}
try {
con=DriverManager.getConnection(CONNSTRING,DB_USERNAME,DB_PASSWORD);
sql=con.createStatement();
sql.executeUpdate("update bb_operator set password='"+npwd+"' where oper_id="+oper_id);
sql.close();
con.close();
}
catch(SQLException e) {}
%>
<script language="javascript">
alert("您的密码修改成功!请使用新密码登陆!谢谢!^_^");
window.parent.location.href=('index.jsp');
</script>
<%
}
else
{
%>
<script language="javascript">
alert("旧密码输入错误,请重新输入!^_^");
</script>
<%
}
rs2.close();
sql2.close();
con2.close();
}
catch(SQLException e) {}
%>