首页 > 开发 > PHP > 正文

php 验证用户名重复

2024-05-04 21:58:28
字体:
来源:转载
供稿:网友

PHP实例代码如下:

  1. $uid = $_request['uid']; 
  2. checkusername($uid); 
  3. function checkusername() 
  4.  $title = $uid
  5.  ifemptyempty$title ) ) 
  6.  { 
  7.   return false; 
  8.  } 
  9.  else 
  10.  { 
  11.   mysql教程_connect('localhost','root','root'); 
  12.   mysql_select_db('test'); 
  13.   mysql_query("set names 'gb2312'"); 
  14.   $sql = "select * from cn_user where username ='$title'"
  15.    
  16.   $row = mysql_query($sql); 
  17.    
  18.   if( mysql_num_rows( $row ) ) 
  19.   { 
  20.    echo '用户名己经存'
  21.   } 
  22.   else 
  23.   { 
  24.    return '可以注册'
  25.   } 
  26.  } 

SQL数据库代码如下:

  1. /* 
  2. create table `test`.`cn_user` ( 
  3. `id` int not null auto_increment , 
  4. `username` varchar( 20 ) not null , 
  5. `times` date null , 
  6. primary key ( `id` )  
  7. ) engine = myisam 
  8.  
  9. 插入数据 
  10.  
  11. insert into `test`.`cn_user` ( 
  12. `id` , 
  13. `username` , 
  14. `times`  
  15. values ( 
  16. null , 'jimmy'null  
  17. ), ( 
  18. null , 'www.Vevb.com'null  
  19. ); 
  20.  
  21. */ 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表