| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3152 人关注过本帖
标题:求助:注册时检测用户名是否可用?
只看楼主 加入收藏
suoyuan888
Rank: 2
等 级:论坛游民
帖 子:58
专家分:16
注 册:2009-8-24
结帖率:92.86%
收藏
已结贴  问题点数:15 回复次数:9 
求助:注册时检测用户名是否可用?
请高手指教:当点击检测用户名时,为什么没有反应,而在网页的左下角会出现,网页有错误的提示呢?
Userreg.html
<FORM name='UserReg' action='UserRegPost.asp' method='post'>
                          <table width=95% border=0 align="center" cellpadding=5 cellspacing=1 bordercolor="#FFFFFF" style="border-collapse: collapse">
                            <TR align=center>
                              <TD height=20 colSpan=2><b>新用户注册</b></TD>
                            </TR>
                            <TR>
                              <TD width="37%"><b>用户名:</b><BR>
                                不能小于4个字符(2个汉字)</TD>
                              <TD width="63%"> <INPUT   maxLength=14 size=30 name=UserName>
                                <font color="#FF0000">*</font>  <input name="Check" type="button" id="Check" value="检查用户名" onClick="checkreg();"></TD>
                            </TR>
                            <TR>
                              <TD width="37%"><B>密码(至少6位):</B><BR>
                                请输入密码,区分大小写。 不要使用类似 '*'、' '的特殊字符</TD>
                              <TD width="63%"> <INPUT   type=password maxLength=12 size=30 name=Password>
                                <font color="#FF0000">*</font> </TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>确认密码(至少6位):</strong><BR>
                              </TD>
                              <TD width="63%"> <INPUT   type=password maxLength=12 size=30 name=PwdConfirm>
                                <font color="#FF0000">*</font> </TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>密码问题:</strong><BR>
                                忘记密码的提示问题</TD>
                              <TD width="63%"> <INPUT   type=text maxLength=50 size=30 name="Question">
                                <font color="#FF0000">*</font> </TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>问题答案:</strong><BR>
                                忘记密码的提示问题答案,用于取回密码</TD>
                              <TD width="63%"> <INPUT   type=text maxLength=20 size=30 name="Answer">
                                <font color="#FF0000">*</font> </TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>性别:</strong><BR>
                                请选择您的性别</TD>
                              <TD width="63%"> <INPUT type=radio CHECKED value="1" name=sex>
                                男 &nbsp;&nbsp; <INPUT type=radio value="0" name=sex>
                                女</TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>Email地址:</strong><BR>
                                请输入有效的邮件地址</TD>
                              <TD width="63%"> <INPUT   maxLength=50 size=30 name=Email>
                                <font color="#FF0000">*</font></TD>
                            </TR>
                            <TR>
                              <TD><strong>公司网址:</strong></TD>
                              <TD width="63%"><INPUT name=homepage id="homepage" value="http://" size=30   maxLength=50></TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>公司名称:</strong><BR>
                                您的公司名称</TD>
                              <TD width="63%"> <INPUT name=CompanyName id="CompanyName" size=30   maxLength=100></TD>
                            </TR>
                            <TR>
                              <TD><strong>收货地址:</strong></TD>
                              <TD><INPUT name=Add id="Add" size=30   maxLength=100>
                                <font color="#FF0000">*</font></TD>
                            </TR>
                            <TR>
                              <TD><strong>收货人:</strong></TD>
                              <TD><INPUT name=Receiver id="Receiver" size=30   maxLength=100></TD>
                            </TR>
                            <TR>
                              <TD><strong>邮政编码:</strong></TD>
                              <TD width="63%"><input name=postcode id="postcode" size=30 maxlength=20>
                                <font color="#FF0000">*</font></TD>
                            </TR>
                            <TR>
                              <TD><strong>联系电话:<br>
                                </strong>格式010-81991660<strong> </strong></TD>
                              <TD width="63%"><input name=Phone id="Phone" size=30 maxlength=20>
                                <font color="#FF0000">*</font></TD>
                            </TR>
                            <TR>
                              <TD><strong>手机:</strong></TD>
                              <TD><input name=Mobile id="Mobile" size=30 maxlength=20></TD>
                            </TR>
                            <TR>
                              <TD width="37%"><strong>传 真:</strong></TD>
                              <TD width="63%"> <INPUT name=Fax id="Fax" size=30 maxLength=50></TD>
                            </TR>
                          </TABLE>
                  <div align="center">
                    <INPUT   type=submit value=" 注 册 " name=Submit>
                    &nbsp;
                    <INPUT name=Reset   type=reset id="Reset" value=" 清 除 ">
                  </div>
                </form>
                        <form name='reg' action='../UserCheckreg.asp' method='post' target='CheckReg'>
          <input type='hidden' name='username' value=''>
        </form><!-Plist_Bottom->


UserCheckRegl.asp
<!--#include file="Inc/conn.asp"-->
<!--#include file="Inc/function.asp"-->
<%
dim UserName,FoundErr,ErrMsg

UserName=trim(request("UserName"))
Response.Write(UserName)
if UserName="" or strLength(UserName)>14 or strLength(UserName)<4 then
    founderr=true
    errmsg=errmsg & "<br><li>请输入用户名(不能大于14小于4)</li>"
else
      if Instr(UserName,"=")>0 or Instr(UserName,"%")>0 or Instr(UserName,chr(32))>0 or Instr(UserName,"?")>0 or Instr(UserName,"&")>0 or Instr(UserName,";")>0 or Instr(UserName,",")>0 or Instr(UserName,"'")>0 or Instr(UserName,",")>0 or Instr(UserName,chr(34))>0 or Instr(UserName,chr(9))>0 or Instr(UserName,"?")>0 or Instr(UserName,"$")>0 then
        errmsg=errmsg+"<br><li>用户名中含有非法字符</li>"
        founderr=true
    end if
end if
if founderr=false then
    dim sqlCheckReg,rsCheckReg
    sqlCheckReg="select * from [User] where UserName='" & Username & "'"
    set rsCheckReg=server.createobject("adodb.recordset")
    rsCheckReg.open sqlCheckReg,conn,1,1
    if not(rsCheckReg.bof and rsCheckReg.eof) then
        founderr=true
        errmsg=errmsg & "<br><li>“" & UserName & "”已经存在!请换一个用户名再试试!</li>"
    else
    end if
    rsCheckReg.close
    set rsCheckReg=nothing
end if        
%>
<html>
<head>
<title>检查用户名</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="mt_style.css" type=text/css rel=stylesheet>
</head>

<body>
<br>
<%
if founderr=false then
    call Success()
else
    call WriteErrmsg()
end if
%>
</body>
</html>
<%
call CloseConn

sub WriteErrMsg()
    response.write "<table align='center' width='300' border='0' cellpadding='2' cellspacing='0' class='border'>"
    response.write "<tr class='title'><td align='center' height='15'>错误提示</td></tr>"
    response.write "<tr class='tdbg'><td align='left' height='100'>" & errmsg & "<p align='center'>【<a href='javascript:onclick=window.close()'>关 闭</a>】<br></p></td></tr>"
    response.write "</table>"
end sub

sub Success()
    response.write "<table align='center' width='300' border='0' cellpadding='2' cellspacing='0' class='border'>"
    response.write "<tr class='title'><td align='center' height='15'>恭喜你!</td></tr>"
    response.write "<tr class='tdbg'><td align='left' height='100'><br>“" & UserName & "”尚未被人使用,赶紧注册吧!<p align='center'>【<a href='javascript:onclick=window.close()'>关 闭</a>】<br></p></td></tr>"
    response.write "</table>"
end sub
%>
搜索更多相关主题的帖子: 用户名 注册 检测 
2010-01-06 14:32
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
程序代码:
<script language="javascript">
function checkname(sname) {  //该函数用来获取数据
 var xmlhttp1=createAjax(); 
 if (xmlhttp1) {  
  var span=document.getElementById('check');  // 获取显示节点
 xmlhttp1.open('get','checkuser.asp?tname='+sname+'&n='+Math.random(),true);
  xmlhttp1.onreadystatechange=function() {  
   if (xmlhttp1.readyState==4 && xmlhttp1.status==200) { 
    span.innerHTML=unescape(xmlhttp1.responseText); 
    }
   else {
    span.innerHTML="<span style='color:red'>xmlhttp对象正在初始化......</span>";
    
     
   }
 
  }
  xmlhttp1.send(null); 
 }
}



</script>

<input name="login_name" type="text" id="login_name" value="<%=request("login_name")%>" onBlur="checkname(this.value);" size="18">
                  <font color="#FF0000">*</font><span id="check"></span>

checkuser.asp
程序代码:
<!-- #include file="../inc/data_conn.asp" -->
<%
' 添加数据库连接
dim sql,user
quser=trim(request("tname")) ' 获取用户名并过滤非法字符
if quser="" then 
Response.Write escape("<font color='#ff0000'>用户名不能为空</font>")
response.End()
end if
sql="select userid from company where userid='"&quser&"'" ' 查询数据库中是否有重复记录
set rs = conn.execute(sql)

If not(rs.Eof And rs.Bof) Then
Response.Write escape("<font color='#ff0000'>已经存在此成员名 请更换</font>") ' 返回结果并进行编码转义
Else
Response.Write escape("<font color='#ff0000'>此用户名可以注册</font>")
end if
%>




这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2010-01-06 14:47
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:0 
checkreg这个函数在哪里?
2010-01-06 14:48
suoyuan888
Rank: 2
等 级:论坛游民
帖 子:58
专家分:16
注 册:2009-8-24
收藏
得分:0 
回复 2楼 孤独冷雨
谢谢!
没看懂—— 不知道您写的代码应该放在我的页面的哪个位置?
2010-01-06 16:48
suoyuan888
Rank: 2
等 级:论坛游民
帖 子:58
专家分:16
注 册:2009-8-24
收藏
得分:0 
回复 3楼 aspic
这个函数没有找到—— 好像根本没有
2010-01-06 16:49
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
checkreg()函数不存在当然会报错

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2010-01-06 17:03
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:10 

JS代码你直接在<head></head>之间贴上去.
程序代码:
<script language="javascript">
function checkname(sname) {  //该函数用来获取数据
var xmlhttp1=createAjax(); 
if (xmlhttp1) {  
  var span=document.getElementById('check');  // 获取显示节点
xmlhttp1.open('get','checkuser.asp?tname='+sname+'&n='+Math.random(),true);
  xmlhttp1.onreadystatechange=function() {  
   if (xmlhttp1.readyState==4 && xmlhttp1.status==200) { 
    span.innerHTML=unescape(xmlhttp1.responseText); 
    }
   else {
    span.innerHTML="<span style='color:red'>xmlhttp对象正在初始化......</span>";
    
     
   }

  }
  xmlhttp1.send(null); 
}
}
</script>



用户名检测不要用按钮,直接换成:<INPUT maxLength="14" size="30" name="UserName" onBlur="checkname(this.value);" ><font color="#FF0000">*</font><span id="check"></span>
别的不要动。

再新建一个页面叫checkuser.asp,代码是下面这个直接复制进去,你的那个UserCheckRegl.asp就不要了:
程序代码:
<!--#include file="Inc/conn.asp"-->
<%
' 添加数据库连接
dim sql,user
quser=trim(request("tname")) ' 获取用户名并过滤非法字符
if quser="" then 
Response.Write escape("<font color='#ff0000'>用户名不能为空</font>")
response.End()
end if
sql="select username from [User] where username='"&quser&"'" ' 查询数据库中是否有重复记录
set rs = conn.execute(sql)

If not(rs.Eof And rs.Bof) Then
Response.Write escape("<font color='#ff0000'>已经存在此成员名 请更换</font>") ' 返回结果并进行编码转义
Else
Response.Write escape("<font color='#ff0000'>此用户名可以注册</font>")
end if
%>

如果你还不会。你就结帖子不要再问了!

[ 本帖最后由 孤独冷雨 于 2010-1-6 17:24 编辑 ]

这里有男女系列成人用品,有时间兄弟们来看一看.
51za.
2010-01-06 17:18
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:5 
程序代码:
<%
dim quser:quser=trim(request("tname"))
if quser="" then 
   Response.Write("用户名不能为空")
   response.End
end if

If conn.execute("select count(*) from [User] where username='"&quser&"'")>0 Then
   Response.Write("已经存在此成员名 请更换")
Else
   Response.Write("此用户名可以注册")
end if
%>


[ 本帖最后由 hmhz 于 2010-1-6 17:32 编辑 ]

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2010-01-06 17:31
suoyuan888
Rank: 2
等 级:论坛游民
帖 子:58
专家分:16
注 册:2009-8-24
收藏
得分:0 
回复 7楼 孤独冷雨
呵呵,让版主见笑了,初来乍到,对ASP编程还不是很熟悉,希望在这里能得到大家的帮助。
这次版主的话看明白了,这就去试下!谢谢!
2010-01-07 17:41
suoyuan888
Rank: 2
等 级:论坛游民
帖 子:58
专家分:16
注 册:2009-8-24
收藏
得分:0 
回复 8楼 hmhz
这个验证,代码看似很简洁!谢谢!
2010-01-07 17:43
快速回复:求助:注册时检测用户名是否可用?
数据加载中...
 
   



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

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