I am using CakePHP and following its tutorial. I want to update a record but when i do its create another record not updating. according to tutorial my code is given below
$data = array('Id' => $id, 'Approved' => 12);
$this->names->save($data);
it results in
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
4
for keyPRIMARY
And if I do this
$this->names->Id=$id;
It adds a new record. How should I fix this ?
$this->names->id=$id;
$this->names->set(array('Approved'=>12));
$this->names->save();
The key must be id
and not Id
. If in your table you can't use id (lowercase) and you have to use Id (uppercase) then you have to set it in your Model file
also you are not followeing the conventions: the model should be Name and not names (singular and CamelCase)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With