[eluser]LuckyFella73[/eluser]
I have never seen this usage in models and can't find it in the user guide either:
Code:
$this->db->set('user_name',set_value('user_name')); // set_value
Maybe it should work .. don't know
Try the following code and see what you get. Note that you'll have
to
edit the lines around
"$db_data = array(" according to the name
attributes of your input fields!
Code:
# controller:
function save_user()
{
$this->load->library('form_validation');
// this load form validation on cofig folder
if($this->form_validation->run('add_user') == FALSE)
{
$array = '{ "message" : "Input not valid" }';
echo $array;
}
else
{
$this->load->model('User_model');
$db_data = array(
'username' => $this->input-post('username'),
'password' => $this->input-post('username')// and so on
);
$add_data = $this->User_model->add_user($db_data);
if($add_data === FALSE)
{
$array = '{ "message" : "Saving Failed" }';
echo $array;
}
else
{
$array = '{ "message" : "Saving data success" }';
echo $array;
}
}
$this->load->view('add_user');
}
Code:
# model:
function add_user($data)
{
if ( $this->db->insert('users', $data) )
{
return $this->db->insert_id();
}
else
{
return FALSE;
}
}