Bootstrap modal window display condition with Ajax / Post

1

I created a client registration method with Ajax via Post. But somehow my code must contain some error when I establish a certain condition. Note below: When the value returned from register.php is "Registered", I would like it to open a particular Bootstrap modal window with the information that the customer was successfully registered. It happens that in the case below, it should not be correctly recognizing the expression, because it is always jumping to "else" and opening the wrong window. Could you tell me if my "if" condition contains any errors?

// Envio dos dados cadastrais do cliente
jQuery(document).ready(function(){
    jQuery('#cadastrarcliente').submit(function(){
      var dados = jQuery( this ).serialize();
      jQuery.ajax({
        type: "POST",
        url: "cadastrar.php",
        data: dados,
        success: function(data) {

       if (data == "Cadastrado")

            $('#enviocliente').modal();

        else  $('#errologinduplicado').modal();
      

        }

        });      
      return false;
    });
  });

And the PHP code that returns the "Registered" message

<?php ob_start();
include("config.php"); //Arquivo configuração do BD

  //Captura todos os dados informados em login.php
$telefixo = $_POST['telefixo'];
$nome = utf8_decode($_POST['nome']);
$rg = utf8_decode($_POST['rg']);
$cpf = utf8_decode($_POST['cpf']);
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$email = $_POST['email']; 
$sexo = $_POST['sexo'];
$celular = $_POST['celular'];
$cep = $_POST['cep'];
$residencia = $_POST['residencia'];
$endereco = utf8_decode($_POST['endereco']);
$numero = $_POST['numero'];
$cidade = utf8_decode($_POST['cidade']);
$uf = $_POST['uf'];
$pessoa = utf8_decode($_POST['pessoa']); 
$datanasc = $_POST['data'];
$estadocivil = $_POST['estadocivil'];
$profissao = utf8_decode($_POST['profissao']);  
$foto = 'anonymous.jpg'; 

$sql_busca = mysqli_query($bd,"SELECT * FROM user WHERE cpf='$cpf'");
$num_busca = mysqli_num_rows($sql_busca);


// Verifica se já não existe uma credencial com mesmo CPF na tabela user
if ($num_busca == 0) {
 

	  //Se não existir, grava os dados informados na tabela user
 $sql_inclu = "INSERT INTO user (nome, usuario, senha, email, sexo, celular, cep, residencia, endereco, numero, cidade, uf, estadocivil, profissao, pessoa, datanasc, foto, rg, cpf, telefixo) VALUES ('$nome', '$usuario', '$senha', '$email', '$sexo', '$celular', '$cep', '$residencia', '$endereco', '$numero', '$cidade', '$uf', '$estadocivil', '$profissao', '$pessoa', '$datanasc', '$foto', '$rg', '$cpf', '$telefixo')";
 $exe_inclu = mysqli_query ($bd, $sql_inclu);


 echo "Cadastrado";
}


else {
	
 echo "Erro";

}

?>
    
asked by anonymous 25.07.2016 / 07:32

0 answers