Модель POST «Category_Model расширяет CI_Model»:
Код: Выделить всё
public function custom_query($data)
{
$q = $this->db->query($data);
return $q;
}
Код: Выделить всё
public function edit_category()
{
$data['title'] = "Edit Category Page";
$this->load->view('edit_category', $data);
}
public function update_category()
{
$id = $this->input->post('cat_id'); // I try $id = $this->uri->segment(3); but no result
$name = $this->input->post('name');
$desc = $this->input->post('description');
$this->post_model->custom_query("update category set cat_name='" . $name . "', description='" . $desc . "' where cat_id='" . $id . "'"); // when I delete 'where cat_id='" . $id . "'' clause, all my records were changing/updating
// I change to $this->db->where('cat_id', $id); $this->db->update('category'), but no result.
redirect ('category/view_categories');
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/19753214/how-to-update-a-database-record-from-a-form-submission-in-codeigniter[/url]
Мобильная версия