[eluser]Michael Wales[/eluser]
I did read the post from the beginning and I am trying to help. Let's see if we can break this down a little futher:
Here you are inserting 2 columns: action and master_name.
Code:
INSERT INTO `master` (`action`, `master_name`) VALUES (NULL, ‘sdf’)
Here you are inserting 1 column: master_name.
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
$query = $this->db->insert(‘master’, $data);
In the code you have show us, thus far, the only place in which action is referenced is:
Code:
$this->action = 'insert';
So, even though the code you are showing us is this:
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
$query = $this->db->insert(‘master’, $data);
In reality, it looks like this:
Code:
$data = array(‘master_name’ => $this->input->post(‘master_name’));
// ... Do some other stuff here to add an action key to the $data array ...
$query = $this->db->insert(‘master’, $data);
If you would like help in debugging this problem, please share the relevant code in it's entirety.
To do what you want - your code should look something like this:
Code:
class Model_name extends Model {
var $id;
function insert($data) {
$this->db->insert('master', $data);
if ($this->db->affected_rows() > 0) {
$this->id = $this->db->last_insert_id();
return TRUE;
}
return FALSE;
}
}
Code:
class Controller_name extends Controller {
function index() {
$this->load->model('model_name');
if ($this->model_name->insert(array('master_name' => $this->input->post('master_name'))) {
echo 'Inserted ID: ' . $this->model_name->id;
} else {
echo 'Did not insert data.';
}
}
}