Just to clarify all the answers here work flawlessly! I chose Edwins since he posted first.
$this -> load -> model('staff_model');
$this -> load -> library('encrypt');
$arrData = array(
'anum' => $this -> encrypt -> encode($this->input->post('anum')),
'first' => $this -> input -> post('fname'),
'last' => $this -> input -> post('lname'),
'why' => $this -> input -> post('why'),
'aidyear' => $this -> input -> post('aidyear'),
'signintime' => NULL,
'comments' => $this -> input -> post('comments'),
);
if ($insert = $this -> staff_model -> session($arrData)) {
redirect('staff_controller/signin_info');
} else {
$this -> studentlogin();
}
Model :
function session($arrData) {
$null = NULL;
$sql2 = "INSERT INTO session (anum, first, last, why, aidyear, signintime, studentcomments)
VALUES (?, ?, ?, ?, ?, ?, ?)";
$insert = $this -> db -> query($sql2, $arrData);
return $insert;
}
You can't define array variables like this. Try to change to,
$data = array (
'encrypted' => $this->encrypt->encode('anum'),
'first' => $this->input->post('first'),
'last' => $this->input->post('last'),
'aidyear' => $this->input->post('aidyear'),
'why' => $this->input->post('why'),
'comments' => $this->input->post('comments'),
);
Controller
$this -> load -> model('staff_model');
$this -> load -> library('encrypt');
$this->load->library('form_validation');
$this->load->helper('url');
//validate form input
$this->form_validation->set_rules('anum', 'Anum', 'required');
other validation rules
.....
if ($this->form_validation->run() == FALSE)
{
redirect('back to previous page through controller');
}else{
$data = array (
'encrypted' => $this->encrypt->encode('anum'),
'first' => $this->input->post('first'),
'last' => $this->input->post('last'),
'aidyear' => $this->input->post('aidyear'),
'why' => $this->input->post('why'),
'comments' => $this->input->post('comments'),
);
if ($insert = $this -> staff_model -> session($data)) {
print_r($insert);
}
}
Model
function session($data) {
$query= $this->db->insert('session', $data); //insert into session table
return $query->result();
}
Use this in your controller:
$arrData = array();
//use same name as in your database table in array fileds like this
$arrData['anum'] = $this->encrypt->encode('anum');
$arrData['first'] = $this->input->post('first');
$arrData['last'] = $this->input->post('last');
$arrData['aidyear'] = $this->input->post('aidyear');
$arrData['why'] = $this->input->post('why');
$arrData['studentcomments'] = $this->input->post('comments');
if ($this -> staff_model -> session($arrData)) {
redirect('staff_controller/signin_info');
}
And in model just use
// No need to write variable names because we already use same field names in array
function session($arrData)
{
if($this->db->insert($arrData))
return true;
else
return false;
}