沂南县人大:求asp代码

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 19:23:45
在数据库中有admin pwd type 三个字段

admin下有三个用户名分别是 x y c

pwd 下有三个密码分别是 x y c (与上面的三个用户对应)
type 下有三个值(1 2 3)也依次和 x y c 三个用户相对应

我要做一个登录页面,
当用户x 登录的时候在数据库中查询他的type的值,让它进入m.asp页面;
当用户y 登录的时候在数据库中查询他的type的值,让它进入n.asp页面;
当用户c 登录的时候在数据库中查询他的type的值,让它进入r.asp页面;
type 字段下的值是 1 2 3
其中1和用户x对应

2和用户y对应

3和用户c对应
其中登录的时候还要验证一下输入的用户名和密码是不是和数据库中的一样,
用户是不是合法的用户。
在asp代码页用如何写这个语句?
请高手帮忙写一下,谢谢!
用的数据库是access数据库
代码用vbsprint

这样操作.
index.asp内容如下:
*********************************************
<html>
<title>验证用户</title>
<script language="JavaScript">
var errfound = false;

function error(elem, text) {
if (errfound) return;
window.alert(text);
elem.select();
elem.focus();
errfound = true;
}

function loginCheck(f) {

errfound = false;

if (f.admin.value == "")
error(f.admin,"Please enter your user id!");

if (f.pwd.value == "")
error(f.pwd,"Please enter your password!");

return ! errfound;
}
</script>
<body leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<table width="750" height="26" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="242" height="106" border="0" align="center" cellpadding="2" cellspacing="0">
<form action="login.asp" method="post" onSubmit="return loginCheck(this);">
<tr>
<td align="left">User ID</td>
<td><input name="admin" type="TEXT"size="20"></td>
</tr>
<tr>
<td align="left">Password</td>
<td><input name="pwd" TYPE="PASSWORD" size="10"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Login"></td>
<tr>
<td height="30" colspan="2"> </td>
<tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>
*********************************************
login.asp内容
*********************************************
<%
'数据库连接文件
Dim conn
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb")
%>
<%
Function Sqlstr(data)
sqlstr=Replace(data,"'","''")
End Function
admin=sqlstr(request.form("admin"))
pwd=sqlstr(request.form("pwd"))
sql= "select admin,pwd from zhidao where admin='"&admin&"' and pwd='"&pwd&"'"
set rs=conn.execute(sql)
if rs.eof or rs.bof then
%>
<script language="javascript">
alert("用户名或密码输入有误!!")
parent.location.href="index.asp"
</script>
<%else
mysql="select admin,pwd,type from [zhidao] where admin='"&admin&"'"
set rs=Server.CreateObject ("ADODB.RECORDSET")
rs.open mysql,conn,1,3
If rs.Eof Then
Response.Redirect("index.asp")
else
if rs("type")="1" then
Response.Redirect("m.asp")
else if rs("type")="2" then
Response.Redirect("n.asp")
else if rs("type")="3" then
Response.Redirect("r.asp")
end if
end if
end if
end if
end if
%>
*********************************************
数据库名称为database.mdb表段为zhida
不符合你的可以在login.asp中更改.测试可以使用.

这个好说,代码如下:
''先包含一个conn.asp的数据库连接文件,定义一个conn的数据库连接变量,以供不同页面调用。
Dim rs,sql
Dim name,pwd ''两个变量接收用户名和密码
Dim type ''用户类型
Dim url ''跳转页面

name = trim(Request.Form("name"))
pwd = trim(Request.Form("password"))
type = Request.Form("type")

name = Replace(name,"'","''")
pwd = Replace(pwd,"'","''")

Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM user WHERE name='"&name&"' " & _
"AND password='"&pwd&"'"
rs.Open sql,conn,1,1
If Not rs.Eof Then
Select Case type:
Case "1" url = "m.asp"
Case "2" url = "n.asp"
Case "3" url = "r.asp"
End Select
Else
Response.Write "用户名或者密码错误?"
Response.End
End If
Response.Redirect url
rs.Close
Set rs = nothing

<% Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM [user] WHERE admin='"&requst("admin")&"' " & _
"AND pwd='"&request("pwd")&"'"
rs.Open sql,conn,1,1
If rs.Eof Then
Response.Redirect("登录页面")
else
if rs("type")="1" then
Response.Redirect("m.asp")
else if rs("type")="2"
Response.Redirect("n.asp")
else if rs("type")="3"
Response.Redirect("r.asp")
end if
end if
%>