An interesting way to do this is to fill in the field e-mail
you use the method change
jQuery to send an Ajax.
In PHP he will make a select
checking whether this email exists in the database, and if it exists, you can show a message that the email already exists in the success
ajax.
Example:
var email = $("#email");
email.change(function() {
$.ajax({
url: 'teste.php',
type: 'POST',
data: email.val(),
dataType: 'json',
success: function(data) {
console.log(data);
if (data.email) { // se existir
$("#resposta").append('Ja existe um usuario cadastrado com este email');
}
},
error: function() {
$("#resultado").show().fadeOut(5000);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type='text' id='email'>
<div id='resposta'></div>
In php do a test just returning true to see if the return of ajax is working, after that you can do the select
and put the proper return:
$output = true;
echo json_encode($output);
I think that would be enough, would you have a practical example of this? Or at least a similar solution? Grateful!
– Sr. André Baill
I use the Codeigniter
– Sr. André Baill
It didn’t work... Points error in jQuery
– Sr. André Baill
@Andrébaill in php you just need to select and resume if there is an email I believe it is not difficult to modify the code to perform this in codeigniter, as for the error in jquery which would it be ?
– Gabriel Rodrigues
@gustavox did you have any idea what might be going on? I couldn’t even elaborate.
– Sr. André Baill
it returns nothing... As much as I search only on the variable, without entering mysql... does not return...
– Sr. André Baill
Could you elaborate another example? In this one I couldn’t.. From PHP I can elaborate the mysql questions, I just don’t understand anything from jquery.. @gabrielrodrigues
– Sr. André Baill
I’m sorry @Andrébaill, I just edited to correct some small inaccuracies of the text... but look, it doesn’t return any errors? This kind of situation is complicated to help, because by relying on external file (PHP and Json) it is difficult to create a verifiable example (for those who try to help can go testing)... but just for the record, you said that it does not return anything, but the page stops running? Because if you get an infinite loop, it could be a PHP error.
– gustavox
Yes, normal... But the result does not come, and I entered the console and points jQuery error.
– Sr. André Baill
@Andrébaill edited the answer making it simpler, do a test, here it works.
– Gabriel Rodrigues
I answered the question differently: http://answall.com/questions/76686/verifi-se-o-email-filled-j%C3%A1-exists-in-database-without-refresh
– Sr. André Baill