ASP+代码的用户登录 5
2个回答
展开全部
<table>
<tr><form method="POST" action="">
<td align="right">用户:</td>
<td><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="pass" size="20"></td>
</tr>
<tr>
<td><input type="submit" value="登录" name="submit"></td>
</tr></form>
</table>
<%
if request("submit")="登录" then
user=request.form("user") '得到user的值
pass=request.form("pass") '得到pass的值
'_____________以下是连接数据库_________________________
Set Conn=Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.Recordset")
DbPath=Server.Mappath("数据库路径")
Conn.Open ("Provider=Microsoft.OLEDB.JET.4.0;Data Source="& DbPath)
sql="select * from users where username='"& user &"'" and password='"& pass &"'" '检查用户名和密码
rs.open sql,conn,1,1
if rs.eof then
response.write "没有该用户"
else
session("username")=rs("username")
response.write "登陆成功!"
end if '结束查询
end if '结束登陆
%>
<tr><form method="POST" action="">
<td align="right">用户:</td>
<td><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="pass" size="20"></td>
</tr>
<tr>
<td><input type="submit" value="登录" name="submit"></td>
</tr></form>
</table>
<%
if request("submit")="登录" then
user=request.form("user") '得到user的值
pass=request.form("pass") '得到pass的值
'_____________以下是连接数据库_________________________
Set Conn=Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.Recordset")
DbPath=Server.Mappath("数据库路径")
Conn.Open ("Provider=Microsoft.OLEDB.JET.4.0;Data Source="& DbPath)
sql="select * from users where username='"& user &"'" and password='"& pass &"'" '检查用户名和密码
rs.open sql,conn,1,1
if rs.eof then
response.write "没有该用户"
else
session("username")=rs("username")
response.write "登陆成功!"
end if '结束查询
end if '结束登陆
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户登录</title>
</head>
<body>
<%
if request("cmd")="login" then
user=request.form("user")
pass=request.form("pass")
Dim Conn
Dim Rs
Dim DbPath
Set Conn=Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.Recordset")
DbPath=Server.Mappath("数据库路径")
Conn.Open ("Provider=Microsoft.OLEDB.JET.4.0;Data Source="& DbPath)
sql="select * from [表名] where [用户字段]='"& user &"'" and [密码字段]='"& pass &"'"
rs.open sql,conn,1,1
if rs.eof then
response.write ("<script language=""javascript"">alert(""没有该用户"");location.href(""index.asp"")</script>")
response.end
else
response.write ("<script language=""javascript"">alert(""登录成功"");location.href(""bangong.asp"")</script>")
end if
end if
%>
<form method="POST" action="index.asp?cmd=login">
<div align="center">
<table border="0" width="400" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td align="right">用户:</td>
<td><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="pass" size="20"></td>
</tr>
<tr>
<td align="right"> </td>
<td><input type="submit" value="登录" name="B1"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户登录</title>
</head>
<body>
<%
if request("cmd")="login" then
user=request.form("user")
pass=request.form("pass")
Dim Conn
Dim Rs
Dim DbPath
Set Conn=Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.Recordset")
DbPath=Server.Mappath("数据库路径")
Conn.Open ("Provider=Microsoft.OLEDB.JET.4.0;Data Source="& DbPath)
sql="select * from [表名] where [用户字段]='"& user &"'" and [密码字段]='"& pass &"'"
rs.open sql,conn,1,1
if rs.eof then
response.write ("<script language=""javascript"">alert(""没有该用户"");location.href(""index.asp"")</script>")
response.end
else
response.write ("<script language=""javascript"">alert(""登录成功"");location.href(""bangong.asp"")</script>")
end if
end if
%>
<form method="POST" action="index.asp?cmd=login">
<div align="center">
<table border="0" width="400" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td align="right">用户:</td>
<td><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="pass" size="20"></td>
</tr>
<tr>
<td align="right"> </td>
<td><input type="submit" value="登录" name="B1"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询