Note that there are some explanatory texts on larger screens.

plurals
  1. PO$this->Model->save() : what's is wrong with this code?
    text
    copied!<p>I am a beginner in cakePHP , i want to save some data into my database , but i always get : the Message : <strong>Sorry, Error while saving data.</strong> </p> <p>Here is my code : ( Controller : <code>UsersController.php</code> : ( and i have added the Model 'UserState to the array <code>$uses</code> ) </p> <pre><code>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-&gt;UserState-&gt;save($newUserState)){ $response['success'] = 'true'; $response['message'] = ''; }else{ $response['success'] = 'false'; $response['message'] = 'Sorry, Error while saving data.'; } </code></pre> <p>Thanks in advance</p> <p><strong>EDIT :</strong> Structure of the table userstates : </p> <p><strong>id : BIGINT primary key AUTO INCREMENT, user_id : INT NOT NULL, user_status : SMALLINT NOT NULL, user_phone_nb = VARCHAR(15) NULL</strong></p> <p>the Model Userstate : </p> <pre><code>class Userstate extends AppModel { var $useTable = 'userstates'; public $name = 'UserState'; } </code></pre> <p><strong>EDIT 2 :</strong> </p> <p>when i debugg the variable $newUserState i got this ( which seems that is OK ) : </p> <pre><code>Array ( [UserState] =&gt; Array ( [user_id] =&gt; 18 [user_status] =&gt; 0 [user_phone_nb] =&gt; 4343 ) ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload