ASP+Access用戶登錄代碼,其中
huiyuan.mdb數據庫名
pUser213 表名
y_username用戶名字段,y_passWord密碼字段.
login.htm頁面
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=gb2312">
<title>登錄</title>
</head>
<body>
<p> </p>
<form name="form1" method="post" action="loginnew.ASP">
<table width="200" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><div align="center">登錄</div></td>
</tr>
<tr>
<td width="57"><div align="center">用戶名</div></td>
<td width="137" valign="top"><input name="username" type="text"
id="username" size="25"></td>
</tr>
<tr>
<td><div align="center">密碼</div></td>
<td valign="top"><input name="password" type="passWord"
id="passWord" size="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="提交">
</div></td>
</tr>
</table>
</form>
</body>
</Html>
loginnew.ASP網頁
<%
dim username,passWord
username=request.form("username")
password=request.form("passWord")
set rs=server.createobject("adodb.recordset")
conn = "DBQ=" + server.mappath("huiyuan.mdb") + ";DefaultDir=;
DRIVER={Microsoft Access Driver (*.mdb)};"
sql="select * from pUser213 where y_username='"&username&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "<script>alert('登錄失敗');history.back();</script>"
response.end
else
if rs("y_password")<>passWord then
response.write "<script>alert('登錄失敗');history.back();</script>"
response.end
end if
session("admin")=username
response.write"<script>alert('登錄成功');location.href='index.ASP'</script>"
end if
%>