首页 > 开发 > PHP > 正文

php 验证用户名重复

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

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.Vevb.com', null  
  20. ); 
  21.  
  22. */ 

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