Problem to Capture Error BD Codeigniter

0

I would like to know why it does not give the error number when I enter a wrong value in the Database.

This is the Function of the Model ...

<?php

class Pacientes_model extends CI_Model {

function __construct() {
    parent::__construct();
}

 public function insertar($datos_paciente) {
    $sql = "INSERT INTO pacientes (cod_tii_paciente, no_ide_paciente,nom1_paciente, nom2_paciente, ape1_paciente, ape2_paciente, sexo_paciente, cod_est_civil_paciente,fec_nac_paciente, cod_ocup_paciente, dir_paciente, tel_paciente, cel_paciente) "
            . "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
    $resultado = $query_result = $this->db->query($sql, $datos_paciente);
    if ($resultado) {
         return $this->db->affected_rows();  
    } else {
        return  $this->db->_error_number(); 
    }
}
}

This is the driver code

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Pacientes extends CI_Controller {

public function __construct() {
    parent::__construct();
    $this->load->model('Pacientes_model');

}

public function clientes() {
    $this->load->model('pacientes_model');

}

public function guardar() {
    if ($this->input->is_ajax_request()) 
    $datos_paciente = ['cod_tii_paciente' => $this->input->post('sel_ti'),
        'no_ide_paciente' => $this->input->post('text_nro_ide'),
        'nom1_paciente' => trim(strtolower($this->input->post('text_nom1'))),
        'nom2_paciente' => trim(strtolower($this->input->post('text_nom2'))),
        'ape1_paciente' => trim(strtolower($this->input->post('text_ape1'))),
        'ape2_paciente' => trim(strtolower($this->input->post('text_ape2'))),
        'sexo_paciente' => $this->input->post('sel_sexo'),
        'cod_est_civil_paciente' => $this->input->post('sel_ec'),
        'fec_nac_paciente' => $this->input->post('text_fec_nac'),
        'cod_ocup_paciente' => $this->input->post('text_cod_ocup'),
        'dir_paciente' => trim(strtolower($this->input->post('text_dir'))),
        'tel_paciente' => trim($this->input->post('text_tel')),
        'cel_paciente' => trim($this->input->post('text_cel'))];

    $message = $this->Pacientes_model->insertar($datos_paciente);

    if ($message) {
        echo $message;
    } else {
        echo $message;
    }
}

}
}
    
asked by ganedugo 23.09.2016 в 18:02
source

1 answer

0

Gentlemen are using very bad programming practices, Codeigniter is a framework that has many advantages and offers a powerful mechanism to manage the requests of the models. The error it presents is 500, it is an error due to a bad procedure in the file where it says that the error was found and the server simply stops compiling and shows error. If you want to fix that error you just have to create a function in the controller where you capture the data and send it to the model, for example:

    public function add() {
        //Te falta agregar codigo de llamada del modelo que usas
        $this->form_validation->set_rules('nombre', 'Nombre', 'required');
        $this->form_validation->set_rules('campoX', 'campoX', 'required');
        if (!empty($_POST)) {
            if ($this->form_validation->run() == TRUE) {
                $values = array('nombre' => $_POST['nombre'],'campoX' => $_POST['campoX']);
                $new = $this->default_model->insert($values);
                redirect('pacientes');
            }
        }
        $data['title_page'] = 'Adicionar Enlace';
        $this->load->view('top', $data);
        $this->load->view('pacientes/add', $data);
        $this->load->view('down', $data);
    }

Then that would be the code for the controller, and the model code is as follows:

function insertar($datos) {
    return $this->db->insert('nombre_tabla', $datos);
}

If you do not understand well you can contact me to give you a better explanation.

    
answered by 18.10.2016 в 05:47