It does not insert me in php and it does not show the error

0

When saving it does not insert and it does not show any error, how can I capture the error and show it on the screen? .Thank you.

//class.establecimiento.php
<?php

function __construct()
{
    parent::__construct(); //estamos conectados
}

//listar tabla
public function getEstablecimientos(){
    $sql = "
      SELECT * 
      FROM vestablecimientos
      ORDER BY idpuntoestablecimiento";
    $resultado = $this->conexion->query($sql); 
    return $resultado;   //array
}

public function getPagesEstablecimientos($offset,$per_page){
    $sql = "
      SELECT * 
      FROM vestablecimientos
      ORDER BY idpuntoestablecimiento DESC
      LIMIT $offset,$per_page";
    $resultado = $this->conexion->query($sql);
    return $resultado;   //array
}   

//listar vista
public function getvEstablecimientos(){
    $sql = "SELECT * FROM vestablecimientos";
    $resultado = $this->conexion->query($sql);
    return $resultado;   //array
}

//total de filas
public function getRowsEstablecimientos(){
    $sql = "SELECT count(*) AS numrows FROM puntoestablecimientos";
    $resultado = $this->conexion->query($sql);
    return $resultado;   //array
}

//insertar
public function addEstablecimiento(
      $nombre, $telefono, $direccion,
      $activo, $idcontribuyente
) { 
    $stmt = $this->conexion->prepare('
      INSERT INTO puntoestablecimientos
      VALUES (0,?,?,?,?,?)
    ');
    $stmt->bind_param(
       'ssssi',
       $nombre, $telefono, $direccion,
       $activo, $idcontribuyente
    );
    $stmt->execute();
    $stmt->close();
}

agregarestablecimiento.php

<?php
include '../class/class.establecimientos.php';
$establecimiento = new Establecimiento();

if (isset($_POST['nombre'])) {
    $nombre = $_POST['nombre'];
    $telefono = $_POST['telefono'];
    $direccion = $_POST['direccion'];
    $activo = $_POST['activo'];
    $idcontribuyente = $_POST['idcontribuyente'];

    $establecimiento->addEstablecimiento(
       $nombre, $telefono,
       $direccion, $activo, $idcontribuyente
    );
} else {
    header('Location: ../establecimientos.php'); 
}
?>

establecimientos.js

//boton guardar establecimiento
$('#guardarEstablecimiento').on('click', function(){
    var nombre = $('#nombre').val();
    var telefono = $('#telefono').val();
    var activo = $('#activo').val();
    var idcontribuyente = $('#idcontribuyente').val();
        if (
           nombre.length > 0 && 
           telefono.length > 0 && 
           idcontribuyente.length > 0
        ) { //valida requerido
            $('#mensaje').html('<p></p>');
            var parametros = {
                'nombre' : $('#nombre').val(),
                'telefono' : $('#telefono').val(),
                'direccion' : $('#direccion').val(),
                'activo' : $('#activo').val(),
                'idcontribuyente' : $('#idcontribuyente').val()  
            };              
            $.ajax({  //envia POST a otro php
                type: 'POST',
                url: 'php/agregarestablecimiento.php',
                data: parametros,
                success: function(data){
                    var url = document.URL;
                    location.href = url; 
                }
            });
        } 
        else {
            toastr["error"]("FALTAN ALGUNOS DATOS", "ATENCION");
        }
});
    
asked by Alexis 09.10.2018 в 02:41
source

0 answers