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
}
?> |