检验用户登陆出现的问题。。<以解决>
这是一个检验登陆情况的页面,当输入正确的用户名及密码以后跳到了 index.asp,但是报了以下的错误:这个错误是在index.asp页面中报出来的。。
Script error detected at line 98.
Source line: = Session("Name")
Description: 缺少语句
<%
'去除表单数据中的空格
UserName = Trim (Request.Form("name"))
UserPass = Trim (Request.Form("passwd"))
SafeCode = Trim(Request.Form("SafeCode"))
'用户名、密码、验证码都必须填写
If (UserName="" Or UserPass="" Or SafeCode="") Then
Response.Redirect "login.asp?ErrMsg=请完整填写登陆表格"
Response.End()
End If
'检验验证码的输入是否正确
If (SafeCode <> Session("SafeCode")) Then
Response.Redirect "login.asp?ErrMsg=请输入正确的验证码"
Response.End()
End If
Dim objConn, strSQL, objRS
'建立与数据库的连接
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=SQLOLEDB;Data Source=ylof;Initial Catalog=MEMBER;User ID=sa; PASSWORD=sa"
objConn.Open
'检索数据库中是否存在相关记录
strSQL = "Select * From MEMBER Where NAME='" & UserName & "'"
strSQL = strSQL & " And PASSWORD = '" & UserPass & "'"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 1, 3, 1
'检索结果为空,表明用户名或者密码错误
If objRS.EOF Then
Response.Redirect "login.asp?ErrMsg=用户名或密码错误"
Response.End()
Else
'检索记录集不为空,说明用户名和密码输入正确
Session("Id") = CStr(objRS.Fields("ID"))
Session("Name") = UserName
Session("Class") = objRS.Fields("CLASS")
Session("IsPassed")=TRUE
'检查用户的级别
If objRS.Fields("CLASS") = "1" OR objRS.Fields("CLASS") = "2" Then
'该登陆用户为管理员
Session("IsAdmin") = TRUE
Else
'该登陆用户为普通用户
Session("IsAdmin") = FALSE
End If
'如果用户选择记住帐号和密码,则将其写入cookies
If Request.Form("RemMe") = "1" Then
Response.Cookies("Name") = UserName
Response.Cookies("Password") = UserPass
Response.Cookies("RemMe") = "1"
Response.Cookies("Name").expires = Date + 365
Response.Cookies("Password").expires = Date + 365
Response.Cookies("RemMe").expires = Date + 365
End If
End If
'关闭记录集和数据库连接
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
'转向系统主页面
Response.Redirect "index.asp"
Response.End()
%>
以下是index.asp页的代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'检查用户是否已经登陆,为真则直接进入系统主界面
If Session("IsPassed") = EMPTY Or Session("IsPassed") = FALSE Then
'检查Cookies,是否有保存的用户信息
If Request.Cookies("RemMe") ="1" Then
'存在Cookies信息,自动进行登陆操作
UserName = Request.Cookies("Name")
UserPass = Request.Cookies("Password")
Dim objConn, strSQL, objRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=SQLOLEDB;Data Source=ylof;Initial Catalog=MEMBER;User ID=sa; PASSWORD=sa"
objConn.Open
strSQL = "Select * From MEMBER Where NAME='" & UserName & "'"
strSQL = strSQL & " And PASSWORD = '" & UserPass & "'"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 1, 3, 1
'是否存在这个用户
If NOT objRS.EOF Then
Session("Id") = CStr(objRS.Fields("ID"))
Session("Name")=UserName
Session("IsPassed")=TRUE
Session("Class") = objRS.Fields("CLASS")
'检索记录集不为空,说明用户名和密码输入正确
'检查用户的级别
If objRS.Fields("CLASS") = "1" OR objRS.Fields("CLASS") = "2" Then
'该登陆用户为管理员
Session("IsAdmin") = TRUE
Else
'该登陆用户为普通用户
Session("IsAdmin") = FALSE
End If
'更新Cookies
Response.Cookies("Name") = UserName
Response.Cookies("Password") = UserPass
Response.Cookies("RemMe") = "1"
Response.Cookies("Name").expires = Date + 365
Response.Cookies("Password").expires = Date + 365
Response.Cookies("RemMe").expires = Date + 365
Else
'Cookies中的用户名或密码错误,返回login.asp要求重新登陆
Response.Redirect "login.asp?ErrMsg=用户名或密码错误"
Response.End
End If
'关闭数据集和数据库连接
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Else
'没有登陆,也不存在Cookies信息,返回login.asp要求先登陆
Response.Redirect "login.asp?ErrMsg=请先登陆"
Response.End
End If
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>系统主页面</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style2 {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 56px;
}
-->
</style>
</head>
<body>
<table width="750" border="0" align="center">
<tr>
<td align="center"><div class="style2">用户登录及管理系统</div></td>
</tr>
<tr>
<td><hr size="2"></td>
</tr>
<tr>
<td height="40"> </td>
</tr>
<tr>
<td>
<div align="center" class="style1">
登陆成功!
<%
= Session("Name")
%> , 欢迎你的到来!
</div>
</td>
</tr>
<tr>
<td height="40"> </td>
</tr>
<tr>
<td> <div align="center" class="style1">
<%
If Session("IsAdmin") = TRUE Then
%>
<a href="admin.asp">会员管理</a>
<%
End If
%>
<a href="modify.asp?id=
<%
= Session("Id")
%>">修改信息</a><a href="logout.asp">退出登陆</a></div>
</td>
</tr>
</table>
<br>
</body>
</html>
红色部分为报错的位置。。
找了很久不知道错在哪里,GGJJ们可以为我解答一下么
红色的位置改为:
<% = session("Name")%>
<a href="modify.asp?id=<% = session("Id")%>">修改信息</a>
[[it] 本帖最后由 awke002 于 2008-9-3 10:44 编辑 [/it]]