Welcome Guest, Not a member yet? Register   Sign In
Can't update primary key
#4

(11-08-2016, 05:28 PM)uglyaditya Wrote: i follow your suggest and this my model:

PHP Code:
// update data
 
   function update($id$data)
 
   {    
        
$this->db->where('nis'$id);
        
$this->db->update($this->table$data);
 
   

or i try this too:
PHP Code:
// update data
 
   function update($id$data)
 
   {    
        
$this->db->where($this->id$id);
        
$this->db->update($this->table$data);
 
   

it's still not working.


Hi! As for update goes, you can update the rest of the columns by keeping the primary key as anchor.  But in your case you are trying to update primary key too ('nis').

Change your controller's update_action() function like this,

PHP Code:
public function update_action()
{
 
   ...
 
   
    
} else {
 
       $data = array(
 
       'nama' => $this->input->post('nama',TRUE),
 
       'jkel' => $this->input->post('jkel',TRUE),
 
       'active' => $this->input->post('active',TRUE),
 
       );

 
   ...
 
   }


And what @cartalot suggested is also true.  You have to use where clause in model's update() function to let the db know what record should be updated.

Your model fn should be this,
PHP Code:
function update($id$data)
   
    $this
->db->where('nis'$id);
 
   $this->db->update($this->table$data);


Hope this helps Smile
Reply


Messages In This Thread
Can't update primary key - by uglyaditya - 11-07-2016, 08:39 PM
RE: Can't update primary key - by cartalot - 11-08-2016, 04:16 PM
RE: Can't update primary key - by uglyaditya - 11-08-2016, 05:28 PM
RE: Can't update primary key - by KimZ - 11-09-2016, 09:20 AM
RE: Can't update primary key - by uglyaditya - 11-25-2016, 01:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB