ASP防止重名注册

原理很简单,通过一句SQL语句:Select * from student where stname='"+stname+"' 接着就开始检查,当到(rs.eof)记录的最后一条还找不到时stname,说明这个名字(stname)没有被注册 则值行下面的动作,把他注删的信息进行添加。。。 详细代码如下:

 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>ASP 防止重名注册</title> 
<%  
'数据库的连接  
dim connstr  
connstr="provider=microsoft.jet.oledb.4.0;data source=" + server.mappath ("db1.mdb")  
set conn=server.createobject("adodb.connection")  
conn.open connstr  
%> 
<%  
if request("send")="ok" then  
 dim stname  
 stname = Request.Form("stname")  
 if stname = "" then  
  response.write "<mce:script type="text/javascript"><!--  
alert('你没有输入用户名');  
// --></mce:script>"  
  response.end  
 end if   
 sqlStr="Select * from student where stname='"+stname+"'"   
    Set rs=Server.CreateObject("Adodb.RecordSet")  
    rs.open sqlStr,conn,1,3  
 if not(rs.bof and rs.eof) then  
  Response.Write "<mce:script type="text/javascript"><!--  
alert('您的用户名已被注册!');window.location.href('index.asp');  
// --></mce:script>"  
 else  
  rs.Addnew             
  rs("stname")=Request.Form("stname")           
  rs.Update  
  Response.Write "<mce:script type="text/javascript"><!--  
alert('注册成功!');window.location.href('index.asp');  
// --></mce:script>"  
    end if  
 rs.close  
 set rs=nothing 
 response.end  
end if  
 
%> 
</head> 
 
<body> 
<form id="form1" name="form1" method="post" action="index.asp"> 
  <label> 
  <input name="stname" type="text" id="stname" value="" size="45" /> 
  </label> 
  <label> 
  <input type="submit" name="button" id="button" value="提交" /> 
  <input type="hidden" name="send" value="ok" /> 
  </label> 
</form> 
</body> 
</html> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值