fsp712 fsp712 - 1 year ago 99
PHP Question

codeigniter update method not working

I am new to codeigniter and trying to write an update function to update information in my database. I've gone through a few tutorials but for some reason my code is not working! Any tips or assistance would be greatly appreciated. I'm just testing with two fields right now, name and email, and I get a blank page when I go to my update view.

Here is my model method:

function get_by_id($id){
return $this->db->get_where('table',array('id'=>$id));

function update($id){
'name'=> $this->input->post('Name'),
'email'=> $this->input->post('Email')
return $this->db->where('id',$id)

And here is my relevant controller code:

function edit(){
$data['name']= 'Name';
$this->load->view('updateview', $data);

function update($id){

redirect('kittens/view/'.$id, 'refresh');

And here is my update view:

<?php echo form_open('kittens/update/')
echo form_hidden('id', $row[0]->id);

foreach($attributes as $field_name){
echo '<p>' . $field_name;
echo form_input($field_name, $row[0]->$field_name) . '</p>';
echo form_submit('', 'Update');

echo form_close();

Any help would be appreciated! Not sure what specific part is giving me the trouble!

Answer Source

Use the following template:


public function updateData(){
 $data = array(
  "columnName" => $columnValue
 $whereValue = $someNumber;
 $this->model_name->updateTable($data, $wherevalue);


public function updateTable($data, $whereValue){
 $this->db->where('columnName', $whereValue);
 $this->db->update('tableName', $data);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download