E-mail evaluation

1

I have a problem analyzing email in a form of register, what I would like to do is that once the user enters his email in the email field, the site already evaluates the email in the database to know if he is available to register. Otherwise, please note below that the email is unavailable.

Could someone tell me the process to do this?

    
asked by anonymous 20.04.2016 / 17:48

1 answer

1

I needed it and developed it:

jQuery:

var email = $("#usuario_email");
    email.blur(function() {
        $.ajax({ 
            url: "/outras/verificaEmail.php",
            method: "POST",
            cache: false,
            data: {"usuario_email": $("#usuario_email").val()},
            dataType: "json",       
            success: function(data) {
                console.log("usuario_email");
                console.log(data);
                $("#resposta").text(data.email);
            },
            error: function(a, b, c) {
                console.log(a);
                console.log(b);
                console.log(c); 
            }
    }); 
}); 

HTML:

<label for="inputType" class="col-md-2 control-label">E-mail de Acesso</label>
<div class="col-md-4">
    <input type="email" class="form-control" id="usuario_email" name="usuario_email" placeholder="Digite seu E-mail">
    <div id='resposta'></div>
</div>

PHP:

#Verifica se tem um email para pesquisa
if(isset($_POST['usuario_email'])){

    #Recebe o Email Postado
    $emailPostado = $_POST['usuario_email'];

    #Conecta banco de dados
    $con = mysqli_connect("localhost", "root", "", "outras");
    $sql = mysqli_query($con, "SELECT * FROM cadastrousuarios WHERE usuario_email = '{$emailPostado}'") or print mysql_error();

    #Se o retorno for maior do que zero, diz que já existe um.
    if(mysqli_num_rows($sql)>0){
        echo json_encode(array('email' => 'Ja existe um usuário cadastrado com este email.'));
    } else { 
        echo json_encode(array('email' => 'Parabéns! Você poderá usar este e-mail como usuário.' ));
    }
}

I think it's the most compatible solution at the moment I know to help you.

    
28.04.2016 / 03:53