Home > Backend Development > PHP Tutorial > php+jquery ajax email address verification example without refresh_PHP tutorial

php+jquery ajax email address verification example without refresh_PHP tutorial

WBOY
Release: 2016-07-13 10:49:01
Original
1116 people have browsed it

To achieve a non-refresh page, we usually use ajax to achieve it. In the past, we used the most primitive js ajax for verification. Now we use the commonly used jquery ajax. Just a simple post can solve the problem. Let's look at the example below

index .php page


<script><br> $(document).ready(function(){<br> $('#username').keyup(username_check);<br> });<br> <br> function username_check(){ <br> var username = $('#username').val();<br> if(username == "" || username.length < 4){<br> $('#username').css('border', '3px #CCC solid');<br> $('#tick').hide();<br> }else{</table> jQuery.ajax({<br> Type: "POST",<br> URL: "check.php",<br> Data: 'username='+ username,<br> cache: false,<br> Success: function(response){<br> if(response == 1){<br> //Cannot register<br> $('#username').css('border', '3px #C33 solid'); <br> $('#tick').hide();<br> $('#cross').fadeIn();<br> }else{<br> $('#username').css('border', '3px #090 solid');<br> $('#cross').hide();<br> $('#tick').fadeIn();<br> } }<br> });<br> } } </script>
Username:


php verification page, this page receives the data from jquery ajax post for verification and returns the value
The code is as follows
 代码如下 复制代码





php jquery check username ajax检查帐号唯一性


<script><br> $(document).ready(function(){<br> $('#username').keyup(username_check);<br> });<br>  <br> function username_check(){ <br> var username = $('#username').val();<br> if(username == "" || username.length < 4){<br> $('#username').css('border', '3px #CCC solid');<br> $('#tick').hide();<br> }else{</p> <p>jQuery.ajax({<br>    type: "POST",<br>    url: "check.php",<br>    data: 'username='+ username,<br>    cache: false,<br>    success: function(response){<br> if(response == 1){<br>  //不可以注册<br>  $('#username').css('border', '3px #C33 solid'); <br>  $('#tick').hide();<br>  $('#cross').fadeIn();<br>  }else{<br>  $('#username').css('border', '3px #090 solid');<br>  $('#cross').hide();<br>  $('#tick').fadeIn();<br>       }</p> <p>}<br> });<br> }</p> <p> </p> <p>}</p> <p></script>


Username:


Copy code

 代码如下 复制代码

# 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 "非常好,MYSQL连接成功了!";
//} else {
//echo "不好意思,失败了!";
//}
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)) {
//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";//不能注册

}
?>




php jquery check username ajax check account uniqueness
The code is as follows Copy code
<🎜># 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, 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)) {
//email passed the check
$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 register<🎜> <🎜>}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632749.htmlTechArticleTo achieve a non-refresh page, we usually use ajax to achieve it. In the past, we used the most original js ajax verification now. Commonly used jquery ajax can be solved with a simple post. Below we...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template