I am trying to do a simple update where I pass an array from the Controller to the Model. But I am getting the following error:
Error Number: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near 'id #29
Here is the array that is being passed:
<?
$data = Array
(
[name] => last_name
[value] => Smith
[pk] => 611
);
CONTROLLER
<?
function edit_client() {
$data = $this->input->post();
$this->load->model('clients_model');
$this->clients_model->update_client_info($data);
}
MODEL
<?
function update_client_info($data) {
$update = $this->db->set($data['name'], $data['value']);
$this->db->where('id', $data['pk']);
$this->db->update('clients', $update);
}
Any ideas what I'm doing wrong here?
The problem is in your $this->db->set()
function.
Do the following
$this->db->set('name',$data['name']);
$this->db->set('value',$data['value']);
$this->db->where('id', $data['pk']);
$this->db->update('clients');
That should do the trick. When you use the $this->db->set()
, you need not pass anything other than the table name to the insert or update functions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.