请教各位:我作了个登录验证的网页,但是想在登录成功的同时,在库中增加一条记录。但无论怎样,只是能验证登录,不能增加记录。头都大了也找不出原因。代码如下,想前各位帮忙看一看。谢谢!
登录代码:
<!--#include file="dbconn.asp" -->
<script language="vbscript" src="users.vbs" runat="server"></script>
<%
Response.Expires = 0
Function checkenter()
If username<>"" and password<>"" and otherpwd<>"" and Instr(username,"'")<1 and Instr(username," ")<1 and Instr(username,"""")<1 and Instr(username,"&")<1 then
checkenter=TRUE '允许进行用户验证
Else
checkenter=FALSE '不允许进行用户验证
End If
End Function
Function checksysUser() '系统用户验证
sql="SELECT * FROM fdb_man WHERE user='"&username&"'"
Set rs=Server.CreateObject("adodb.recordset")
rs.Open sql,conn,1,1
if rs.eof then
checksysUser=FALSE
Session("passed")=False
else
passwd=trim(rs("pwd"))
if passwd=password then
checksysUser=TRUE
Session("passed")=True
Session("level")=rs("level")
Session("admin")=rs("admin")
else
checksysUser=FALSE
Session("passed")=False
end if
End if
rs.close
conn.close
End Function
%>
<HTML>
<HEAD>
<TITLE>用户分级登录、有效性验证</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function window_onload() {
document.login.username.focus();
}
function cancel()
{
login.reset();
}
function IsValid()
{
if (document.login.username.value=="")
{
alert("用户名不能为空");
document.login.username.focus();
return false;
}
if (document.login.password.value=="")
{
alert("密码不能为空");
document.login.password.focus();
return false;
}
if (document.login.otherpwd.value=="")
{
alert("附加码不能为空");
document.login.otherpwd.focus();
return false;
}
}
//-->
</script>
<link rel="stylesheet" href="css/style.css" type="text/css">
</HEAD>
<BODY bgColor=#FFFFFF topMargin=0 leftmargin="0" onload="return window_onload()">
<p align="center"><b><font size="6" color="#6699FF">欢迎你登录</font></b></p>
<%
if Request.Form("action")="true" then
username=trim(Request.Form("username")) '登录用户名
password=trim(Request.Form("password")) '登录密码
otherpwd = Trim(Request.form("otherpwd")) '附加码
reotherpwd = Trim(Request.form("reotherpwd"))'生成的附加码
legalTag=checkenter()
If legalTag=TRUE then '如果没有非法输入,则进行用户验证
if otherpwd = reotherpwd then '附加码比较
legalUserTag=checksysUser() '系统用户验证
if legalUserTag=true then
If Session("level")=1 and Session("admin")="True" Then
Response.Redirect("manage.asp")
Response.End
End If
If Session("level")=2 Then
Call AddWords
Response.Redirect("main.asp")
Response.End
End If
If Session("level")=3 Then
Call AddWords
Response.Redirect("normal.asp")
Response.End
End If
else
errmsg="<font color=#FF0000><b>用户名或者用户密码错误,请重新输入!</b></font>"
end if
else
errmsg="<font color=#FF0000><b>附加码输入错误,请重新输入!</b></font>"
end if
else
errmsg="<font color=#FF0000><b>用户名输入有误,请重新输入!</b></font>"
end if
end if
%>
<div align="center"><%=errmsg%><br></div>
<div align="center">
<table width="917" height="50" border="0" cellpadding="0" cellspacing="0">
<form name=login action="index.asp" onSubmit="return IsValid();" method=post>
<tr>
<td height="25" width="4"> </td>
<td valign="top" height="25">
<table cellspacing=0 cellpadding=0 width=624 border=0 align="center" height="43">
<tbody>
<tr>
<td height="43" style="line-height:150%" width="501">
<font size="3">姓 名:
<input type="text" name="username" size="13" class="button1">
密 码:<input type="password" name="password" size="11" class="button1">
附加码:<input type="text" name="otherpwd" size="11" class="button1"></font></tr>
<td height="43" style="line-height:150%" width="4"> <font size="3">
</font>
<td height="43" style="line-height:150%"> <font size="3">
</font><font face="Arial, Helvetica, sans-serif" size="3">
<%
dim temprnd
Randomize
temprnd=cstr(Int((9999 - 1000 + 1) * Rnd() + 1000))
response.Write (temprnd)
%></font><font size="3"><input type="hidden" name="action" value="true"><input type="hidden" name="reotherpwd" value="<%=temprnd%>"></font></td>
</tbody>
</table>
</td>
<td width="202" height="30">
<input type=image height=30 width=62 src="images/btn_login_ok.gif" border=0 name=submit1>
<img onMouseOver="event.srcElement.style.cursor='hand'" onClick=cancel() height=30 src="images/btn_login_cancel.gif" width=62 border=0></td>
</tr>
</form>
</table>
</div>
<hr>
</BODY>
</HTML>
还有users.vbs文件如下:
Function AddWords(user, recordtime)
Dim mysql
mysql = "INSERT INTO record" & "(user, recordtime) "
Set objConn = Session("objConn")
objConn.execute mysql, rdsaffected
If rdsaffected = 0 Then
AddWords = False
Else
AddWords = True
End If
End Function
[此贴子已经被作者于2007-11-8 21:00:16编辑过]