php ajax注册验证用户名是否存在代码

这是注册程序是一款当用户输入完用户名是,就会自动去数据库中查询用户要注册的用户名是否己经被注册了,如果是返回提示否则提示可以注册。

conn.php文件

  1. <html> 
  2. <head> 
  3. <meta http-equiv="content-type" content="text/html; charset=utf-8"
  4. <script > 
  5. var xmlhttp 
  6. function showhint(str) 
  7. if (str.length==0) 
  8.   {  
  9.   document.getelementbyid("txthint").innerhtml="" 
  10.   return 
  11.   } 
  12. xmlhttp=getxmlhttpobject() 
  13. if (xmlhttp==null) 
  14.   { 
  15.   alert ("browser does not support http request"
  16.   return 
  17.   }  
  18. xmlhttp.onreadystatechange=statechanged 
  19. var geturl="conn.php?q="+str 
  20. //sid是增加一个随机数 防止页面启用缓存技术· 
  21. geturl=geturl+"&sid="+math.random() 
  22. geturl=encodeuri(geturl); 
  23. geturl=encodeuri(geturl);  
  24. xmlhttp.open("get",geturl,true) 
  25. xmlhttp.send(null) 
  26. }  
  27. function statechanged()  
  28. {  
  29. if (xmlhttp.readystate==4 || xmlhttp.readystate=="complete"
  30.  {  
  31.  document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext  
  32.  }  
  33. function getxmlhttpobject() 
  34. var xmlhttp=null; 
  35. try 
  36.  { 
  37.  // firefox, opera 8.0+, safari 
  38.  xmlhttp=new xmlhttprequest(); 
  39.  } 
  40. catch (e) 
  41.  { 
  42.  // internet explorer 
  43.  try 
  44.   { 
  45.   xmlhttp=new activexobject("msxml2.xmlhttp"); 
  46.   } 
  47.  catch (e) 
  48.   { 
  49.   xmlhttp=new activexobject("microsoft.xmlhttp"); 
  50.   } 
  51.  } 
  52. return xmlhttp; 
  53. </script>  
  54. </head> 
  55. <body bgcolor="#999999"
  56. <center> 
  57. <form>  
  58. <table> 
  59.  <tr> 
  60.   <td>用户名:</td> 
  61.   <td><input type="text" id="txt1" onkeyup="showhint(this.value)"></td> 
  62.  </tr> 
  63.  <tr align="center"
  64.   <td colspan="2"><span id="txthint"></span></td> 
  65.  </tr> 
  66. </table> 
  67. </form> 
  68. </center> 
  69. </body> 
  70. </html> 
  71.  
  72. <?php 
  73. $q=$_get["q"]; 
  74. $q = urldecode($q); 
  75. if (strlen($q) > 0) 
  76.   $conn = @mysql_connect("localhost","root","1010"or die ("mysql连接错误"); 
  77.   mysql_select_db("xin",$conn); 
  78.   mysql_query("set names 'utf8'"); 
  79.    
  80.   $sql = "select username from message where username = '$q'"
  81.   $query = mysql_query($sql); 
  82.   @$row = mysql_fetch_array($query); 
  83.    
  84.   if(!emptyempty($row['username'])) 
  85.   { 
  86.    $response = "<font color=red>已经被注册!</font>"
  87.   }else 
  88.   { 
  89.    $response = "<font color=blue>恭喜!可以注册!</font>"
  90.   } 
  91.    
  92.   echo $response
  93. ?> 

数据库

  1. drop database if exists `xin`; 
  2. create database `xin` /*!40100 default character set utf8 */; 
  3. use `xin`; 
  4.  
  5. create table `message` ( 
  6.   `id` int(11) not null auto_increment, 
  7.   `username` varchar(20) default null
  8.   primary key  (`id`) 
  9. ) engine=innodb auto_increment=2 default charset=utf8; 
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php ajax注册验证用户名是否存在代码

57 评论

  1. buy fildena generic methocarbamol cost robaxin 500mg without prescription

  2. olmesartan 20mg sale calan 240mg price buy acetazolamide 250mg pills

  3. buy dapsone sale adalat cost order aceon online

  4. order accutane 40mg online accutane 40mg us prednisone 40mg usa

  5. buy metoprolol generic brand lopressor vardenafil online buy

  6. sildalis medication sildalis sale lamictal buy online

  7. win real money online casino stromectol 6mg uk buy generic provigil 100mg

  8. order terbinafine 250mg for sale suprax 100mg sale cheap trimox 500mg

  9. help writing research paper leflunomide ca sulfasalazine 500 mg tablet

  10. usa cialis sales Cialis store sildenafil 150mg price

  11. buy cialis 40mg online top ed drugs ed pills that work quickly

  12. alfuzosin without prescription trazodone 50mg ca buy diltiazem 180mg generic

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡