请帮我看看这段asp代码错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/05/29 08:51:02
default.asp

<html>
<head>
<meta http-equiv="Cache_Control" content="max-age=0"/>
</head>
<body>

<form name="form1" method="post" action="login.asp" onSubmit="return chkform(this)">
<td >用户名</td>
<td > <input name="User" maxlength="10" type="text" emptyok="false"/>
</td>

<tr>
<td>密码</td>
<input name="Pwrd" maxlength="10" type="password" emptyok="false"/>

</tr>
<tr>
<td ><input type="submit" name="Submit" value="登陆"></td>
</tr>

</form>
</body>
</html>

login.asp

<%

虽然你SQL语句有了,但是recordset都没有打开,怎么可能会有数据出来,你的rs.eof怎么会有用?
应该在SQL="..."后面加上:
set rs=server.createobject("adodb.recordset")
rs.open SQL,conn,1,1
而且还要在页面最后把conn和rs都关掉及清除掉
rs.close
set rs=nothing
conn.close
set conn=nothing

回复修改后的login.asp:

1、微软推荐使用OLEDB连接数据库:

conn.Open("provider=microsoft.jet.oledb.4.0;data source="&
Server.MapPath("wapdb.mdb"))

2、把SQL语句放到rs.open前面,不然SQL为空又怎么能open;

3、注意你的SQL:

SQL="select UserID,UserName from users"&"where username='"&Username&"'and password ='"&Passw&"'"

users"&"where这里错了,"&"前面或后面需要一个空格,其实这里也没有必要这样写,改成这样:

SQL="select UserID,UserName from [users] where username='"&Username&"' and password='"&Passw&"'"

4、养成在ASP中用response.write(SQL)检查语句错误的习惯。

首先你要告诉我们你的出错