| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 704 人关注过本帖
标题:[求助]登录验证并添加一条记录的问题?
只看楼主 加入收藏
云中的雨
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-3-19
收藏
 问题点数:0 回复次数:6 
[求助]登录验证并添加一条记录的问题?

请教各位:我作了个登录验证的网页,但是想在登录成功的同时,在库中增加一条记录。但无论怎样,只是能验证登录,不能增加记录。头都大了也找不出原因。代码如下,想前各位帮忙看一看。谢谢!
登录代码:
<!--#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">姓&nbsp;&nbsp;名:
<input type="text" name="username" size="13" class="button1">
密&nbsp;&nbsp;码:<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">&nbsp;
</font>
<td height="43" style="line-height:150%"> <font size="3">&nbsp;
</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编辑过]

搜索更多相关主题的帖子: username Instr 验证 script 
2007-11-08 20:58
t是变量
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2007-11-4
收藏
得分:0 
这个“mysql”用得真是……

社会主义好!社会主义好!社会主义国家人民地位高!
2007-11-08 21:09
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
呵呵,用的很牛吧!

这个东西复杂的很,搞不过来

[此贴子已经被作者于2007-11-8 23:41:23编辑过]


[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2007-11-08 23:40
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
楼上的楼上的楼上,你的错误是什么得帖出来啊,这么一大对发出来叫人看有没错,想累我们老人家吗?

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2007-11-08 23:46
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
总算看完了,问题出在这里
mysql = "INSERT INTO record" & "(user, recordtime) "
mysql = "INSERT INTO record" & "(user, recordtime) values('"&user&"','"&recordtime&"')"

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2007-11-09 00:02
zhongx
Rank: 2
等 级:论坛游民
威 望:1
帖 子:370
专家分:42
注 册:2007-8-16
收藏
得分:0 
以下是引用hmhz在2007-11-8 23:46:51的发言:
楼上的楼上的楼上,你的错误是什么得帖出来啊,这么一大对发出来叫人看有没错,想累我们老人家吗?

有点幽默!


感动常在,每天进步一点点,开心学习在编程论坛。
http://www.
2007-11-09 13:48
云中的雨
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-3-19
收藏
得分:0 

各位说看不明白,我再申明一遍,就是要在用户登录时,同时在数据库的另一个记录表中增加一条登录时间记录.我把登录的代码重改如下:
<%@ LANGUAGE="VBScript" %>
<html>
<head>
<script language="VBScript">
<!--
Sub login_OnClick
Dim msg
msg = ""
If fus.stxm.value = "" Then
msg = "姓名不能为空!请先选择..."
fus.stxm.focus
End If
If msg = "" Then
fus.submit
ElseIf fus.pwd.value = "" Then
msg = "密码不能为空!请先输入..."
fus.stid.focus
ElseIf Len(fus.pwd.value) < 4 Or _
Not IsNumeric(fus.pwd.value) Then
msg = "密码由4位数字组成!请修改..."
fus.pwd.focus
Else
Alert(msg)
End If
End Sub

Sub reset_OnClick
fus.pwd.value = ""
fus.stxm.value = ""
fus.pwd.focus
End Sub
-->
</script>
</head>
<body onload="reset_OnClick">
<center>
<h2>用户登录网页</h2><hr>
<center>
<form name="fus" action="denluxianshi.asp" method="post" target="result">
<table>
<tr><td colspan="6"><font color="blue">用户信息</font></td></tr>
<tr><td colspan="6"><hr></td></tr>
<tr>
<td>姓名</td>
<td><input name="stxm" type="text" maxlength="8" size="10">&nbsp;</td>
<td>密码</td>
<td><input name="pwd" type="password" maxlength="8" size="10">&nbsp;</td>
<td><input name="login" type="button" value="登录">&nbsp;</td>
<td><input name="reset" type="button" value="重设"></td>
<tr><td colspan="6"><hr></td></tr>
<tr><td colspan="6"><font color="blue">登录结果</font></td></tr>
</table>
</form>
</center>
</body>
</html>
能登录,不能增加记录.再次请教并感谢!

[此贴子已经被作者于2007-11-9 15:54:36编辑过]

2007-11-09 15:53
快速回复:[求助]登录验证并添加一条记录的问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028371 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved