Hol I have problems with my code PHP , the header if REGISTER that means that everything is fine but when I want to recover the ID I get the error I do not know if the error is in my controller when calling that id or in my model when it comes to consulting about the last ID .
Driver:
public function guardar_venta() {
$id_cliente = $this->input->post('id_cliente');
$descuento = $this->input->post('descuento');
$efectivo = $this->input->post('efectivo');
$vuelto = $this->input->post('vuelto');
$total = $this->input->post('total');
$detalle = $this->input->post('detalle');
$this->venta->guardar_cabecera($id_cliente, $descuento, $efectivo, $vuelto, $total);
$id_cabecera = $this->input->post('id_venta');
if (isset($id_cabecera)) {
if ($detalle != "[") {
$array_detalle = json_decode($detalle);
foreach ($array_detalle as $objeto) {
$id_producto = $objeto->id_producto;
$cantidad = $objeto->cantidad;
$precio = $objeto->precio;
$subtotal = $objeto->subtotal;
$this->venta->guardar_detalle($id_cabecera, $id_producto, $cantidad, $precio, $subtotal);
}
}
echo 1;
}
}
Model:
public function guardar_cabecera($id_cliente, $descuento, $efectivo, $vuelto, $total) {
$this->db_caja->reconnect();
$this->db_caja->query("INSERT INTO venta VALUES(null,'$id_cliente','$descuento','$efectivo','$vuelto','$total',NOW());");
return $this->db_caja->insert_id();
}
public function guardar_detalle($id_cabecera, $id_producto, $cantidad, $precio, $subtotal) {
$this->db_caja->reconnect();
$query = $this->db_caja->query("INSERT INTO detalle_venta VALUES (null,'$id_cabecera','$id_producto','$cantidad','$precio','$subtotal');");
return $query->result();
}