这门没学过老师就要我们做真的不会啊!!
急用,高手请教啊
谢谢啦
这很简单啊,
先建一个数据库,里面表名usercount
字段名:username,password
数据库连接: conn.asp
<% '数据库连接
dim conn
dim connstr
connstr="DBQ="+server.mappath("bbs.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver
(*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
%>
登录页:login.asp
<form name=form1 action="chk.asp" method="submit">
用户名:<input type=text name=username size=20><br>
密码:<input type=password name=password size=20><br>
<input type=submit value="登录">
</form>
验证页:chk.asp
<!--#include file="conn.asp"-->
<%
unm=request("username")
pws=request("password")
set rs=server.createobjet("adodb.recordset")
sql="select * from usercount where username='" & unm & "' and password='" & pws & "'"
rs.open sql,conn,1,1
if rs.eof then
response.write "用户名或密码错误!"
else
session("username")=rs("username")
session("password")=rs("password")
response.write "登录成功,你的用户名是" & session("username")
end if
%>
<!--#include file="conn.asp"-->
<script language="javascript">
function check()
{
if (document.form1.username.value=="")
{
alert("请输入用户名");
document.form1.username.focus();
return false;
}
if (document.form1.pass.value=="")
{
alert("请输入密码");
document.form1.pass.focus();
return false;
}
document.form1.ctype.value="add";
document.form1.submit();
}
</script>
<%
user=cstr(trim(request("username")))
pass=cstr(trim(request("pass")))
if request("ctype")="add" then
sql="select * from admin where user='"&user&"' and pass='"&pass&"'"
set rs1=conn.execute(sql)
if rs1.eof then
response.Write("<script language=javascript>alert('用户名或密码错误,请重新登陆');self.location.href='login.asp';</script>")
response.End()
else
session("adminuser")=rs1("user")
response.Redirect("admin.asp")
end if
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登陆</title>
</head>
<body>
<table width="780" height="40"><tr><td> </td></tr></table><p>
<center>
<form name="form1" action="" method="get">
<table width="220" cellspacing="2" border="0" cellpadding="2">
<tr><td align="center" colspan="2">登陆图片</td></tr>
<tr><td width="70" align="center">用户名:</td><td width="150"><input type="text" name="username" size=20></td></tr>
<tr><td width=70 align="center">密 码:</td><td width="150"><input type="password" name="pass" size="21"></td></tr>
<tr><td colspan="2" align="center"> <input type="submit" value="登陆" onClick="check()"> <input type="reset" value="取消"><input type="hidden" name="ctype"></td></tr>
<tr><td colspan="2" align="center"><a href="../index.asp">返回首页</a></td></tr>
</table>
</form>
</center>
</body>
</html>