为什么用户名和密码验证不起作用?
我想得到的效果是:用户输入用户名和密码后点击“登录”,程序如果没有在数据库中发现用户输入的用户名或者密码错误,则给出窗口提示并返回登录界面。但是不知道为什么代码不起作用?麻烦大家帮忙看看!
源代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../connections/conn_b.asp"-->
<%
Dim rs,sqlstr
If Not Isempty(Request("login")) Then '判断表单是否提交
txt_name=Str_filter(Request.Form("txtName")) '获取用户名称
txt_passwd=Str_filter(Request.Form("txtPwd")) '获取用户密码
End if
If txt_name<>"" Then '判断用户名是否正确
Set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select P2,pPassword from T_JiChNR where P2='"&txt_name&"'",conn
'rs.open sqlstr,conn,1,1
If rs.eof Then
Response.Write("<script language='javascript'>alert('用户名不正确,请核实后重新输入!');window.location.href='login.asp';</script>")
Else
If rs("pPassword")<>txt_passwd Then
Response.Write("<script language='javascript'>alert('密码不正确,请确认后重新输入!');window.location.href='login.asp';</script>")
End If
End If
Else
errstr="请输入用户名!"
End If
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>系统登陆</title>
<style>
body{
margin-top:12.5%;
margin-left:25%;
background-color:#eee;
font-family:"宋体";
font-size:12px;
}
csm{
font-family:"宋体";
font-size:12px;
}
.input_out{
/*height:16px;默认高度*/
width:180px;
padding:2px 8px 0pt 3px;
height:20px;
border:1px solid #aaa;
background-color:#fff;
list-style-type:none;
}
a{
font-size:12px;
font-family:"宋体";
}
a.bot:link{ /*超链接正常下的样式*/
color:#333333;
text-decoration:none;
}
a.bot:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#333333;
text-decoration:none;
}
a.bot:hover{ /*指针经过时的超链接样式*/
color:#0066FF;
text-decoration:none;
}
a.sev:link{ /*超链接正常下的样式*/
color:#0066cc;
text-decoration:none;
}
a.sev:visited{ /*访问过的超链接样式,此项颜色需要与正常下样式相同,否则在IE 6.0中会出错*/
color:#0066cc;
text-decoration:none;
}
a.sev:hover{ /*指针经过时的超链接样式*/
color:#0066ff;
text-decoration:none;
}
</style>
<script type="text/javascript">
function Mycheck(){
if(document.all.txtName.value==""){
alert('请输入用户名!');return false;}
if(document.all.txtPwd.value==""){
alert('请输入密码!');return false;}
}
</script>
</head>
<body>
<table width="460" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="460" height="237" valign="top" background="../../../picture/Cargo search/login.gif"><table width="459" height="235" border="0">
<tr>
<td height="88" colspan="2"> </td>
</tr>
<form action="C_Search.asp" method="post" name="form1" id="form1">
<tr>
<td width="153" height="23" align="right">用户名:</td>
<td width="296"><input class="input_out" type="text" name="txtName" id="txtName">
</td>
</tr>
<tr>
<td height="28" align="right">密码:</td>
<td><input class="input_out" type="password" name="txtPwd" id="txtPwd">
</td>
</tr>
<tr>
<td height="33" colspan="2" align="center"><input name="login" type="image" id="login" value="提交" src="../../../picture/Cargo search/register.gif" onClick="return Mycheck()"></td>
</tr>
</form>
<tr>
<td> </td>
<td align="right" valign="bottom"><a class="bot" href="../../../index.asp">返回首页</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>