php - codeigniter update method not working -


i new codeigniter , trying write update function update information in database. i've gone through few tutorials reason code not working! tips or assistance appreciated. i'm testing 2 fields right now, name , email, , blank page when go update view.

here model method:

function get_by_id($id){   return $this->db->get_where('table',array('id'=>$id)); }  function update($id){  $attributes=array(     'name'=> $this->input->post('name'),     'email'=> $this->input->post('email')     );   return $this->db->where('id',$id)            ->update('table',$attributes); } 

and here relevant controller code:

function edit(){   $data['row']=$this->mymodel->get_by_id($id)->result();   $data['name']= 'name';   $data['email']='email';   $this->load->view('updateview', $data); }  function update($id){    $this->load->model('mymodel');   $this->mymodel->update($id);   if($this->input->post()){     redirect('kittens/view/'.$id, 'refresh');   } 

and here update view:

<?php echo form_open('kittens/update/') echo form_hidden('id', $row[0]->id);   foreach($attributes $field_name){ echo '<p>' . $field_name; echo form_input($field_name, $row[0]->$field_name) . '</p>'; } echo form_submit('', 'update');   echo form_close(); ?> 

any appreciated! not sure specific part giving me trouble!

use following template:

controller:

public function updatedata(){ ....  $data = array(   "columnname" => $columnvalue  );  $wherevalue = $somenumber;  $this->model_name->updatetable($data, $wherevalue);  ... }     

model:

public function updatetable($data, $wherevalue){  $this->db->where('columnname', $wherevalue);  $this->db->update('tablename', $data); } 

Popular posts from this blog