php 验证用户名重复
PHP实例代码如下:
<?php $uid = $_request['uid']; checkusername($uid); function checkusername() { $title = $uid; if (emptyempty($title)) { return false; } else { mysql_connect('localhost', 'root', 'root'); mysql_select_db('test'); mysql_query("set names 'gb2312'"); $sql = "select * from cn_user where username ='$title'"; $row = mysql_query($sql); if (mysql_num_rows($row)) { echo '用户名己经存'; } else { return '可以注册'; } } } ?>
SQL数据库代码如下:
/* create table `test`.`cn_user` ( `id` int not null auto_increment , `username` varchar( 20 ) not null , `times` date null , primary key ( `id` ) ) engine = myisam 插入数据 insert into `test`.`cn_user` ( `id` , `username` , `times` ) values ( null , 'jimmy', null ), ( null , 'www.phprm.com', null ); */
本文地址:http://www.phprm.com/develop/fs4300.html
转载随意,但请附上文章地址:-)