Having trouble with Codeigniter library
I am working with a codeigniter library called MY_Model.php in that model there is the following function,
public function update($primary_value, $data, $skip_validation = FALSE)
{
$valid = TRUE;
if($skip_validation === FALSE)
{
$valid = $this->_run_validation($data);
}
if($valid)
{
$this->skip_validation = FALSE;
return $this->db->where($this->primary_key, $primary_value)
->set($data)
->update($this->_table);
}
else
{
return FALSE;
}
}
I then executing the function with the following code,
$update = array('last_logged_in', date("Y-m-d H:i:s"));
if($this->ci->users_model->update($query[0]['user_id'], array('last_logged_in', date("Y-m-d H:i:s"))))
{
$this->session->set_flashdata('success', 'You have successfully been logged in');
switch($query['user_type_id'])
{
case 1:
redirect('/candidate/dashboard');
break;
case 2:
redirect('/employer/dashboard');
break;
case 3:
redirect('/admin/dashboard');
break;
}
}
However I am getting the following errors,
A Database Error Occurred
Error Number: 1054
Unknown column '0' in 'field list'
UPDATE
users
SET0
=开发者_运维技巧 'last_logged_in',1
= '2011-04-28 21:06:51' WHEREuser_id
= '2'
Try changing
array('last_logged_in', date("Y-m-d H:i:s"))
to
array('last_logged_in' => date("Y-m-d H:i:s"))
I think you need to change it to this:
if($this->ci->users_model->update($query[0]['user_id'], array('last_logged_in' => date("Y-m-d H:i:s"))))
Note the array is now associative - you had a comma in there making it indexed.
精彩评论