Home Backend Development PHP Tutorial ajax+php verification user name duplicate code example_PHP tutorial

ajax+php verification user name duplicate code example_PHP tutorial

Jul 13, 2016 pm 05:05 PM
ajax php code exist Example Tutorial use user enter repeat verify

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.
*/
?>
<!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>

<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
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";
                                                                   }
}
}
}

</script>

</head>

<body>

<table width="75%" border="0">
<tr>
<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>

</body>

</html>

Save the following code into 忝13.php

<?
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
);

*/
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630819.htmlTechArticle本教程是一款利用了ajax php在用户输入完用户名后,就会发送请求给php程序,然后查询数据,判断用户要注册的用户名是不是己经注册或存在...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

See all articles