me sale este error al momento de insertar datos de un formulario a una base de datos mysql, no se como solucionarlo :(
ajax
<script>
$(document).on("click", "#agregar", function(e){
e.preventDefault();
var nombre = $("#nombre").val();
var apellidop = $("#apellidop").val();
var apellidom = $("#apellidom").val();
var correo = $("#correo").val();
var telefono = $("#telefono").val();
$.ajax({
url: "<?php echo base_url(); ?>insert",
type: "post",
dataType: "json",
data: {
nombre: nombre,
apellidop: apellidop,
apellidom: apellidom,
correo: correo,
telefono: telefono
},
success: function(data){
console.log(data);
}
});
});
</script>
Welcome.php (controller)
***
1. <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->load->model('aplicacion_model'); } public function index() { $this->load->view('welcome_message'); } public function insert(){ if($this->input->is_ajax_request()){ $this->form_validation->set_rules('nombre', 'Nombre', 'required'); $this->form_validation->set_rules('apellidop', 'Apellidop', 'required'); $this->form_validation->set_rules('apellidom', 'Apellidom', 'required'); $this->form_validation->set_rules('correo', 'Correo', 'required|valid_email'); $this->form_validation->set_rules('telefono', 'Telefono', 'required'); if ($this->form_validation->run() == FALSE) { $data = array('responce' => 'error', 'message' => validation_errors()); } else { $ajax_data = $this->input->post(); if($this->aplicacion_model->insert_entry($ajax_data)){ $data = array('responce' => 'success', 'message' => 'Datos agregados con éxito'); }else{ $data = array('responce' => 'error', 'message' => 'Error'); } } }else{ echo "No direct script access allowed"; } echo json_encode($data); } } ***
Aplicacion_model.php
<?php
class Aplicacion_model extends CI_Model {
public function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
public function insert_entry($data)
{
return $this->db->insert('aplicacion', $data);
}
public function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
?>
500
has click ahí y en la pestaña llamadaResponse
te debe salir el detalle del error