0
I’m having trouble creating a Function to make a search in the database and from the zip code complete the fields related to it, as address, neighborhood, city and state.
Obs: I have a mask in the field zip code
Function.php
<?php include("conn.php");
  /* Inicio da função para retornar campos a partir do CEP  GLOBAL */
       function cep($cep, $conn){
          $result = "SELECT * FROM cadcep WHERE cep = '$b_cep' LIMIT 1";
          $resultado = $conn->query($result);
          if($resultado){
              $row = mysqli_fetch_assoc($resultado);
              $valores['tipo_logr'] = $row['tipo_logr'];
              $valores['nome_logr'] = $row['nome_logr'];
              $valores['bairro'] = $row['bairro'];
              $valores['cidade'] = $row['cidade'];
              $valores['estado'] = $row['estado'];
          } else {
              return json_encode(array( 'error' => mysqli_error($conn) ));        
          }
              return json_encode($valores);
      }
      if(isset($_GET['cep'])){
              echo cep($_GET['cep'], $conn);
      }
   /* Fim da função para retornar campos a partir do CEP GLOBAL */
?>
JS to search from zip code
$(document).ready(function(){
          $("#cep").on("change", function(){
               var $tipo_logr = $("select[name='tipo_logr']");
               var $nome_logr = $("input[name='nome_logr']"); 
               var $bairro = $("input[name='bairro']"); 
               var $cidade = $("input[name='cidade']"); 
               var $estado = $("input[name='uf']");
               $.getJSON('function_cep.php',{ 
                       cep: $( this ).val() 
               },function( json ){
                       $tipo_logr.val ( json.tipo_logr );
                       $nome_logr.val ( json.nome_logr );
                       $bairro.val ( json.bairro );
                       $cidade.val ( json.cidade );
                       $estado.val ( json.estado );
               });
       });
});   
You’re missing in Function I’ll create the answer
– Victor
I have a mask, I need to remove it and then carry out the search
– user92870
you need to add the question
– Victor