Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX实时电子邮件验证(PHP)_Php_Jquery_Ajax_Validation - Fatal编程技术网

AJAX实时电子邮件验证(PHP)

AJAX实时电子邮件验证(PHP),php,jquery,ajax,validation,Php,Jquery,Ajax,Validation,当用户在我的网站上创建帐户时,我希望将输入的用户名与我的数据库(MySQL)中的所有当前用户名进行检查,并确认它是否可用 有人知道我可以使用哪些好的库,或者jQuery的插件吗?创建一个以用户名为参数的PHP文件。然后通过jquery中的$.get方法传递它。然后返回一个变量(在我的例子中称为data),该变量将包含PHP文件打印的任何内容 $.get("ajax_available.php?u="+username, function(data){ if(data == "true")

当用户在我的网站上创建帐户时,我希望将输入的用户名与我的数据库(MySQL)中的所有当前用户名进行检查,并确认它是否可用


有人知道我可以使用哪些好的库,或者jQuery的插件吗?

创建一个以用户名为参数的PHP文件。然后通过jquery中的$.get方法传递它。然后返回一个变量(在我的例子中称为data),该变量将包含PHP文件打印的任何内容

$.get("ajax_available.php?u="+username, function(data){
    if(data == "true")
    {
        // username avaiable
            $("#usernameAlert").html("<img src='images/icons/accept.png' 
               title='Laust' /> Username available");
    }
    else
    {
        // username not avaiable
    }
});
$.get(“ajax\u available.php?u=“+用户名,函数(数据)){
如果(数据==“真”)
{
//可用用户名
$(“#usernameAlert”).html(“用户名可用”);
}
其他的
{
//用户名不可用
}
});

在本例中,我的php文件返回字符串“true”,但这只是一个简单的示例。

创建一个以用户名为参数的php文件。然后通过jquery中的$.get方法传递它。然后返回一个变量(在我的例子中称为data),该变量将包含PHP文件打印的任何内容

$.get("ajax_available.php?u="+username, function(data){
    if(data == "true")
    {
        // username avaiable
            $("#usernameAlert").html("<img src='images/icons/accept.png' 
               title='Laust' /> Username available");
    }
    else
    {
        // username not avaiable
    }
});
$.get(“ajax\u available.php?u=“+用户名,函数(数据)){
如果(数据==“真”)
{
//可用用户名
$(“#usernameAlert”).html(“用户名可用”);
}
其他的
{
//用户名不可用
}
});

在本例中,我的php文件返回字符串“true”,但这只是一个简单的示例。

这是未经测试的服务器端代码

<?php
// check_username_available.php?name=(name they supplied)

// this stuff is normally in config.inc.php
$username = "...";  // Mysql username 
$password = "...";  // Mysql password 
$db_name = "...";   // Database name 

// get name supplied from querystring
$name = $_GET('name');

// Connect to server and select database.
//
mysql_connect("localhost", $username, $password) or die("cannot connect to db"); 
mysql_select_db($db_name) or die("cannot select $db_name DB");

$query = "SELECT COUNT(*) FROM 'users' WHERE user_name = '$name'";
$result = mysql_query($query) or die("cannot count rows: " . mysql_error());

header("Content-Type: text/plain");
echo ( 0 < mysql_result($result, 0) ? "false" : "true" );

这是服务器端未经测试的代码

<?php
// check_username_available.php?name=(name they supplied)

// this stuff is normally in config.inc.php
$username = "...";  // Mysql username 
$password = "...";  // Mysql password 
$db_name = "...";   // Database name 

// get name supplied from querystring
$name = $_GET('name');

// Connect to server and select database.
//
mysql_connect("localhost", $username, $password) or die("cannot connect to db"); 
mysql_select_db($db_name) or die("cannot select $db_name DB");

$query = "SELECT COUNT(*) FROM 'users' WHERE user_name = '$name'";
$result = mysql_query($query) or die("cannot count rows: " . mysql_error());

header("Content-Type: text/plain");
echo ( 0 < mysql_result($result, 0) ? "false" : "true" );

示例中给出了您想要的内容。它使用jQuery作为JavaScript库

,示例中给出了您想要的内容。它使用jQuery作为JavaScript库

您将如何自定义它以检查是否提交了正确的电子邮件?您将如何自定义它以检查是否提交了正确的电子邮件?