


ajax+php verification user name duplicate code example_PHP tutorial
Jul 13, 2016 pm 05:05 PMThis 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.
*/
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.bKjia.c0m/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>ajax+php verification user name duplicate code example</title>
</head><script language="Web page special effects">
function createxmlhttprequest(){//Create xmlhttprequest object
if(window.activexobject){//ie
try {
Return new activexobject("microsoft.xmlhttp");
} catch(e){
Return;
}
}else if(window.xmlhttprequest){//mozilla,firefox
try {
Return new xmlhttprequest();
} catch(e){
Return;
}
}
}function getrenews(value){//Main calling function
var xmlhttp=createxmlhttprequest();
var url = "13.php?action=check&title="+value+"&mt="+math.random(300000);
if (value==""){
Return false ;
}
if (xmlhttp){
callback = getreadystatehandler(xmlhttp);
xmlhttp.onreadystatechange = callback;
xmlhttp.open("get", url,true);
xmlhttp.send(null);
}
}function getreadystatehandler(xmlhttp){//Post-processing function returned by the server
</script>
return function (){
if(xmlhttp.readystate == 4){
if(xmlhttp.status == 200){
alert(xmlhttp.responsetext);
If (xmlhttp.responsetext==1){
document.getelementbyid("checkid").innerhtml="<font color='red'>Sorry, the username already exists!</font>";
}else{
Document.getelementbyid("checkid").innerhtml="Can register";
}
}
}
}
<body>
<table width="75%" border="0">
<tr></body>
<td width="12%">Enter user name</td>
<td width="36%">
<input type="text" name="username" id="username" onblur="getrenews(this.value);" />
</td>
<td width="52%" id="checkid"> </td>
</tr>
</table>
</html>
<?
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
);
*/
?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
