I am working on a cakephp 2.x , I want to create a new row or record if the userid is not present in db otherwise update the record, but the problem is: it is not updating the current record. It is creating the record with the userid "0" I dont know the problem is. If is not finding the record it should create a record with the userid which I am giving.
public function activeNoStatus(){
$this->loadModel('Status');
$userid = $this->request->data('idUser');
$notify = $this->request->data('notify');
$data = array();
$data['activeNo'] = $notify;
$count = $this->Status->findUserId($userid);
if($count>0){
$this->Status->id = $userid;
$this->Status->save($data);
echo "update";
}else{
//create new row
$datanew=array();
$this->Status->id = $userid;
$this->request->data['Status']['activeNo']=$notify;
$this->Status->save($this->request->data);
echo "ok";
}
}
It seems idUser field is not autoincrement, In cakePHP documentaion :
So you should make idUser autoincrement Primary key.