Just adapt to your use more follows a practical example.
///PHP code
$campEmail = $_POST['campEmail'];
// faz consulta no banco
$sql = "SELECT * FROM usuarios WHERE email ='".$campEmail.";
$consulta = mysql_query($sql);
$count = mysql_num_rows($consulta);
if(count > 0){
while($linhas = mysql_fetch_array($consulta)) {
echo $linhas["Nome"];
}
}
else{
echo "";
}
///Jquery code
function buscarUsuario() {
var email = $("#cmpEmail").val();
if (email != "" && email != undefined) {
$.ajax({
url: "./buscar.php",
method: "POST",
data: {campEmail: email },
async: false,
cache: false,
success: function (data) {
if (data != "") {
$('#modalConfirm').modal('show');
$('#msgRetorno').text("O usuário " + data + " já foi cadastrado!");
}
else {
$('#modalConfirm').modal('show');
$('#msgRetorno').text("Não existe na base!");
}
},
error: function (jqXHR, textStatus, errorThrown) {
throw "Ocorreu uma falha ao verificar a estabilidade do funcionário, tente novamente.";
}
});
}
else {
$('#modalConfirm').modal('show');
$('#msgRetorno').text("Preencha todos os dados!");
}
}
///Html Modal Code
<div class="modal fade" id="modalConfirm" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p id="msgRetorno"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
What have you tried?
– Jéf Bueno
You can do this using the Modal window, you already have PHP which checks for duplicate record and inserts?
– Sr. André Baill
Yes you can use jquery to validate the fields and ajax to check if there is the record, if yes in the return you will have the answer if yes or no and then just use the modal to display the message
– Rodrigo Santos
Andre, yes I do the check if you already have registration with php. I just wanted to show in Dialog the result.
– netovgs
Rodrigo, Voce would have an example, or easy script to share. I’m new to php, I’m learning reading the forums rs. Thank you
– netovgs
For security reasons I think you should also validate on the server-side
– mrlucasrib