当前位置:首页 > PHP教程 > php应用 > 列表

php 验证用户名重复

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-16 14:05:45 浏览: 评论:0 

PHP实例代码如下:

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

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. ) 
  16. values ( 
  17. null , 'jimmy', null  
  18. ), ( 
  19. null , 'www.phpfensi.com', null  
  20. ); 
  21.  
  22. */ 

Tags: php 验证用户名重复

分享到: