Home > Article > Backend Development > ajax+php verification user name duplicate code example_PHP tutorial
This tutorial uses ajax php. After the user enters the user name, it will send a request to the php program, and then query the data to determine whether the user name the user wants to register has already been registered or is duplicated. In a timely manner The return prompt message is to prevent the user from filling out a large form and suddenly providing a username that cannot be registered and has been registered, which will cause a bad experience. This tutorial is specifically designed to solve this problem. It can quickly tell you whether the user name you want to register can be registered.
Ajax+php tutorial to verify user name duplicate code example
/*
This tutorial uses ajax php. After the user enters the user name, it will send a request to the php program, and then query the data to determine whether the user name to be registered has already been registered or is duplicated, and prompts are returned in a timely manner. Information to prevent users from filling in a large form and suddenly providing a username that cannot be registered and has been registered, which will cause a bad experience. This tutorial is specifically designed to solve this problem. It can quickly tell you whether the user name you want to register can be registered.
*/
?>
Enter user name | |
checkusername();
function checkusername()
{
$title = trim($_get['title']);
if( empty( $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 1;
}
else
{
return null;
}
}
}
/*
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.bKjia.c0m', null
);
*/
?>