Php + jquery ajax email address without refreshing verification instance

Source: Internet
Author: User

Index. php page

The code is as follows: Copy code

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = http://www.111cn.net>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> php jquery check username ajax check account uniqueness </title>
<Link href = "../style.css" rel = "stylesheet" type = "text/css"/>

<Script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"> </script>
<Script>
$ (Document). ready (function (){
$ ('# Username'). keyup (username_check );
});
 
Function username_check (){
Var username = $ ('# username'). val ();
If (username = "" | username. length <4 ){
Certificate ('your username'mirror.css ('border', '3px # CCC solid ');
$ ('# Tick'). hide ();
} Else {

JQuery. ajax ({
Type: "POST ",
Url: "check. php ",
Data: 'username = '+ username,
Cache: false,
Success: function (response ){
If (response = 1 ){
// Cannot be registered
Certificate ('your username'mirror.css ('border', '3px # C33 solid ');
$ ('# Tick'). hide ();
$ ('# Cross'). fadeIn ();
} Else {
Certificate ('your username'mirror.css ('border', '3px #090 solid ');
$ ('# Cross'). hide ();
$ ('# Tick'). fadeIn ();
      }

}
});
}

 

}

</Script>

<Style>
# Username {
Padding: 3px;
Font-size: 18px;
Border: 3px # CCC solid;
}

# Tick {display: none}
# Cross {display: none}
 

</Style>
</Head>

<Body>

Username: <input name = "username" id = "username" type = "text"/>

</Body>
</Html>

Php verification page, which receives data from jquery ajax post for verification and returns the value

The code is as follows: Copy code

<? Php

# FileName = "Connection_php_mysql.htm"
# Type = "MYSQL"
# HTTP = "true"
$ Hostname_lr = "localhost ";
$ Database_lr = "ordersiliconebracelets ";
$ Username_lr = "root ";
$ Password_lr = "";
$ Lr = mysql_pconnect ($ hostname_lr, $ username_lr, $ password_lr) or trigger_error (mysql_error (), E_USER_ERROR );
Mysql_query ("set names utf8 ;");
// If ($ lr ){
// Echo "very good, MYSQL connection successful! ";
//} Else {
// Echo "Sorry, it failed! ";
//}
Mysql_select_db ($ database_lr, $ lr );

//
$ Username = trim (strtolower ($ _ POST ['username']);
$ Username = mysql_escape_string ($ username );

If (eregi ("^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] {2, 3} $ ", $ username )){
// Check the email
$ Query = "SELECT email FROM user WHERE email = '$ username' LIMIT 1 ";
$ Result = mysql_query ($ query );
$ Num = mysql_num_rows ($ result );
 
Echo $ num;
}
Else

{
Echo "1"; // cannot be registered

}
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.