asp如何实现数据库中不同的两个字段分别相同记录只能注册一次限制代码
ifstrcomp(msg,"注册错误信息:")>0thenresponse.Redirect("register.asp?msg="&msg)endififac="ad...
if strcomp(msg,"注册错误信息:")>0 then
response.Redirect("register.asp?msg=" & msg)
end if
if ac="adduser" then
set rsc=server.createobject("adodb.recordset")
sql="select * from accounts where account='"&request.Form("username")&"'"
rsc.open sql,conn,1,1
ck=rsc("account")
set rsc=nothing
if ck<>"" then
msg=msg&"<br>"&"用户名被人注册"
response.Redirect("register.asp?msg="&msg)
end if
if ac="adduser" then
set rsc1=server.createobject("adodb.recordset")
sql="select * from accounts where client_ip='"&request.Form("ip")&"'"
rsc.open sql,conn,1,1
ck=rsc1("client_ip")
set rsc1=nothing
if ck<>"" then
msg=msg&"<br>"&"IP地址已被注册"
response.Redirect("register.asp?msg="&msg)
end if
dsql="select * from accounts where account is null"
set rs=server.createobject("adodb.recordset")
rs.open dsql,conn,1,3
rs.addnew
rs("create_time")=now
rs("account")=request.Form("username")
rs("acc_pwd")=request.Form("password")
rs("remain_credit")=Trim("0")
rs("remain_time")=Trim("0")
rs("block_flag")=Trim("0")
rs("game_block_state")=Trim("0")
rs("login_time")=now
rs("offline_time")=now
rs("online_time")=Trim("0")
rs("client_ip")=request.Form("ip")
rs("block_state_time")=now
rs("gm_level")=Trim("0")
rs.update
set rs=nothing
%>
<center>
<SCRIPT language=JavaScript>alert('注册成功!'); location.href='register.asp'</script>"
</center>
if ac="adduser" then
set rsc1=server.createobject("adodb.recordset")
sql="select * from accounts where client_ip='"&request.Form("ip")&"'"
rsc.open sql,conn,1,1
ck=rsc1("client_ip")
set rsc1=nothing
if ck<>"" then
msg=msg&"<br>"&"IP地址已被注册"
response.Redirect("register.asp?msg="&msg)
end if
如何修改这段代码使其可以正常注册写入数据库。跪求大神帮忙啊 展开
response.Redirect("register.asp?msg=" & msg)
end if
if ac="adduser" then
set rsc=server.createobject("adodb.recordset")
sql="select * from accounts where account='"&request.Form("username")&"'"
rsc.open sql,conn,1,1
ck=rsc("account")
set rsc=nothing
if ck<>"" then
msg=msg&"<br>"&"用户名被人注册"
response.Redirect("register.asp?msg="&msg)
end if
if ac="adduser" then
set rsc1=server.createobject("adodb.recordset")
sql="select * from accounts where client_ip='"&request.Form("ip")&"'"
rsc.open sql,conn,1,1
ck=rsc1("client_ip")
set rsc1=nothing
if ck<>"" then
msg=msg&"<br>"&"IP地址已被注册"
response.Redirect("register.asp?msg="&msg)
end if
dsql="select * from accounts where account is null"
set rs=server.createobject("adodb.recordset")
rs.open dsql,conn,1,3
rs.addnew
rs("create_time")=now
rs("account")=request.Form("username")
rs("acc_pwd")=request.Form("password")
rs("remain_credit")=Trim("0")
rs("remain_time")=Trim("0")
rs("block_flag")=Trim("0")
rs("game_block_state")=Trim("0")
rs("login_time")=now
rs("offline_time")=now
rs("online_time")=Trim("0")
rs("client_ip")=request.Form("ip")
rs("block_state_time")=now
rs("gm_level")=Trim("0")
rs.update
set rs=nothing
%>
<center>
<SCRIPT language=JavaScript>alert('注册成功!'); location.href='register.asp'</script>"
</center>
if ac="adduser" then
set rsc1=server.createobject("adodb.recordset")
sql="select * from accounts where client_ip='"&request.Form("ip")&"'"
rsc.open sql,conn,1,1
ck=rsc1("client_ip")
set rsc1=nothing
if ck<>"" then
msg=msg&"<br>"&"IP地址已被注册"
response.Redirect("register.asp?msg="&msg)
end if
如何修改这段代码使其可以正常注册写入数据库。跪求大神帮忙啊 展开
1个回答
展开全部
创建了太多不必要的对象。
如果是简单获取数据,尽可能不要创建 recordset 对象。
而且,您的程序有被注入的危险。
dim username : username = Trim(Request.Form("username"))
'这里要再加一行程序,转换或判断单引号等符号,以防止在连接SQL语句时,造成SQL注入。
'比如:如果对方输入: ' or 1 = 1,SQL语句可能为: select * from 表 where 字段 = '' or 1 = 1
'那么,就可能会造成SQL注入问题。要小心。
recordset对象是一个比较大型的对象,其包括的功能太多,会造成占用服务器内存,以及程序运行缓慢,如果仅是判断的话,可以这样:
dim result : result = conn.execute("select count(1) from acounts where account='" & username & "'")(0)
这时,只需要判断 result 的值 > 0 那么,其为存在, = 0,那么,其为不存在,即可。而不需要创建recordset对象。以减少耗时,程序的可读性也很高。
也就是说,请善用 connection.execute。
dim result
result = conn.execute("select count(1) from acounts where account='" & username & "'")(0)
if(result > 0) then response.redirect("register.asp?msg=1001") : response.end()
'这里建议使用1001这样的自定义编码来做,而不直接上汉字。好处时,你不需要考虑URL编码问题; 养成习惯后,将来在做多语言版本网站时,也是易用易移值的。
result = conn.execute("select count(1) from acounts where account='" & ip & "'")(0)
if(result > 0) then response.redirect("register.asp?msg=1002") : response.end()
.....(以下从略)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询