php+jquery ajax郵箱地址無重新整理驗證執行個體_PHP教程

來源:互聯網
上載者:User
要實現無重新整理頁面我們一般會用到ajax來實現,以前是使用最原始的js ajax驗證現在常用的jquery ajax了只要簡單的一句post即可解決了,下面我們看執行個體

index.php頁面

代碼如下 複製代碼





php jquery check username ajax檢查帳號唯一性



Username:


php驗證頁面,此頁面接收到jquery ajax post過來的資料進行驗證並傳回值

代碼如下 複製代碼

# 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";//不能註冊

}
?>

http://www.bkjia.com/PHPjc/632749.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632749.htmlTechArticle要實現無重新整理頁面我們一般會用到ajax來實現,以前是使用最原始的js ajax驗證現在常用的jquery ajax了只要簡單的一句post即可解決了,下面我們...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.