Mysql
 sql >> Datenbank >  >> RDS >> Mysql

jQuery-Validator-Plug-In – prüft auf vorhandenen Benutzernamen/E-Mail-Adresse in der MySQL-Datenbank

$.validator.addMethod("checkExists", function(value, element)
{
    var inputElem = $('#register-form :input[name="email"]'),
        data = { "emails" : inputElem.val() },
        eReport = ''; //error report

    $.ajax(
    {
        type: "POST",
        url: validateEmail.php,
        dataType: "json",
        data: data, 
        success: function(returnData)
        {
            if (returnData!== 'true')
            {
              return '<p>This email address is already registered.</p>';
            }
            else
            {
               return true;
            }
        },
        error: function(xhr, textStatus, errorThrown)
        {
            alert('ajax loading error... ... '+url + query);
            return false;
        }
    });

}, '');

ODER

Sie können stattdessen die Remote-Methode verwenden, mit der Sie Remote-Prüfungen durchführen können: http://docs.jquery.com/Plugins/Validation/Methods/remote

Bsp.

    $("#yourFormId").validate({
            rules: {
                email: {
                    required: true,
                    email: true,
                    remote: {
                        url: "checkUnameEmail.php",
                        type: "post"
                     }
                }
            },
            messages: {
                email: {
                    required: "Please Enter Email!",
                    email: "This is not a valid email!",
                    remote: "Email already in use!"
                }
            }
        });

checkUnameEmail.php //zB.

    <?php
    $registeredEmail = array('[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]');

    $requestedEmail  = $_REQUEST['email'];

    if( in_array($requestedEmail, $registeredEmail) ){
        echo 'false';
    }
    else{
        echo 'true';
    }
    ?>