CodeIgniter: Unknown column 'xxx' in 'field list' CodeIgniter: Unknown column 'xxx' in 'field list' codeigniter codeigniter

CodeIgniter: Unknown column 'xxx' in 'field list'


Here is an article I wrote that will help you with debugging CodeIgniter ActiveRecord. Basically use $this->db->last_query() to see what ActiveRecord built your query to be and run it in phpMyAdmin to see if the query itself is valid.

There are a few other tips too, but from what I can see here everything looks fine.

Sneaky tip: you can use:

return !$this->db->affected_rows() == 0;

instead of:

if( $this->db->affected_rows() == 0 ) return false;else return true;


Well, after some hours of harddebuggin' got it working... :P

Same database table structure.

My new model function:

function add_user( $user_data ){    $tbl = $this->db->dbprefix('users');    $this->db->insert($tbl, $user_data);    return !$this->db->affected_rows() == 0;}

My new controller piece of code:

$user_data = array(    'nombre'        => $this->input->post('nombre'),    'apellidos'     => $this->input->post('apellidos'),    'nif'           => $this->input->post('nif'),    'direccion'     => $this->db->escape($this->input->post('direccion')),    'cp'            => $this->input->post('cp'),    'poblacion'     => $this->input->post('poblacion'),    'provincia'     => $this->input->post('provincia'),    'telefono'      => $this->input->post('telefono'),    'edad'          => $this->input->post('edad'),    'retribucion'   => $this->input->post('retribucion'),    'entidad'       => $this->input->post('cc_entidad'),    'oficina'       => $this->input->post('cc_oficina'),    'dc'            => $this->input->post('cc_dc'),    'cc'            => $this->input->post('cc_cc'),    'centro'        => $this->input->post('centro'),    'email'         => $this->input->post('email'),    'especialidad'  => $this->input->post('especialidad'),    'parent'        => $this->session->userdata('parent'));// db addingif( $this->users->add_user($user_data) ){    // logged in!!}else{    // grrr error!!}

It looks much pretty now! :)

Hope this helps some lost souls to DO NOT construct the AR data array into the model, but the controller.