I am a beginner in cakePHP , i want to save some data into my database , but i always get : the Message : Sorry, Error while saving data.
Here is my code : ( Controller : UsersController.php
: ( and i have added the Model 'UserState to the array $uses
)
if($onbreak == 'true'){
$userStatus = 1;
//$response['userStatus'] = 1;
} else {
$userStatus = 0;
//$response['userStatus'] = 0;
}
//add the new user_status to the $newUserState
$newUserState['UserState']['user_id'] = $userID;// $userID = 1
$newUserState['UserState']['user_status'] = $userStatus;
//adding values for fields which should not be NULL
$newUserState['UserState']['user_phone_nb'] = '4343';
//
saving data
if($this->UserState->save($newUserState)){
$response['success'] = 'true';
$response['message'] = '';
}else{
$response['success'] = 'false';
$response['message'] = 'Sorry, Error while saving data.';
}
Thanks in advance
EDIT : Structure of the table userstates :
id : BIGINT primary key AUTO INCREMENT, user_id : INT NOT NULL, user_status : SMALLINT NOT NULL, user_phone_nb = VARCHAR(15) NULL
the Model Userstate :
class Userstate extends AppModel {
var $useTable = 'userstates';
public $name = 'UserState';
}
EDIT 2 :
when i debugg the variable $newUserState i got this ( which seems that is OK ) :
Array
(
[UserState] => Array
(
[user_id] => 18
[user_status] => 0
[user_phone_nb] => 4343
)
)