Save() Not Working

i have the follwoing code in the controller but the save is not working

[b] public function actionPostComment() {

    $model = new SwComment();

    $date = date('Y-m-d H:i:s');

    $parent_id = 0;

    if ($_REQUEST['comment'] == "") {

        echo CJSON::encode(array(

            'status' => 'error',

            'error' => 'please enter some comment..'


    } else {

        $sw_id = $_REQUEST['id'];

        $comments = $_REQUEST['comment'];

        $model->date = $date;

        $model->swid = $sw_id;

        $model->parent_id = $parent_id;

        $model->comments = $comments;

        $model->user_id = 8;

        if ($model->save()) {

            echo CJSON::encode(array(

                'cmnt' => $comments,

                'status' => 'success',


        } else {

            echo CJSON::encode(array(

                'cmnt' => 'data did not enter',

                'status' => 'false',






i have the follwoing content in details.php

[b] <?php

                &#036;form = &#036;this-&gt;beginWidget('CActiveForm', array(

                    'id' =&gt; 'job-form',

                    'enableAjaxValidation' =&gt; true,



                &lt;div class=&quot;submenubar&quot; &gt;

                    &lt;div class=&quot;imageicon&quot;&gt;&lt;/div&gt;

                    &lt;div class=&quot;textfield&quot; id=&quot;textfield&quot;&gt;	   

                        &lt;input id=&quot;q&quot; class=&quot;uname_input&quot; type=&quot;text&quot; name=&quot;comment&quot; title=&quot;Leave a Message&quot; value=&quot;&quot; /&gt;




                echo CHtml::ajaxSubmitButton('post comment', &#036;this-&gt;createUrl('software/postcomment', array('id' =&gt; &#036;model-&gt;swid)), array(

                    'type' =&gt; 'POST',

                    'dataType' =&gt; 'json',

                    'success' =&gt; 'function(data)












any errors? First try $model->save(false) - with false parameter. If that works then remove the false and debug with print_r($model->getErrors()) after $model->save()

Hope this helps

With this code:

if ($_REQUEST['comment'] == "")

You are assuming that ‘comment’ key for $_REQUEST is available.

You should check firstly that ‘comment’ key for $_REQUEST exists, so:

if (isset($_REQUEST['comment'])) { ...

i am printing the succes conditions in another page…

instead of going to the status written inside save it is going to the status written in else

an dthe error is printed…

please check the


how sould i check the above code…

should i simply write it

You can check if you have validation error

if ($model->save())







So if your model cannot be saved because you have validation errors,

you’ll see these errors with var_dump

otherwise u can check also this

if (!$model->hasErrors()) {

				Yii::app()->user->setFlash("success", "Thnaks for Adversiter Regisration.!");

				$this->render('//register/adversiter_register', array('model' => $model, 'venue_inter' => $venue_inter, 'venue_cates' => $venue_cates));


			} else {

				$this->render('//register/adversiter_register', array('model' => $model, 'adver_cates' => $adver_cates));



nothing is getting displayed when i gave the above code

have u not any dispaly error message?


Are you sure that you reach $model->save() line?

Try to put a var_dump inside

if ($model->save())


     var_dump('model should be saved!');



the code is not going inside if ($model->save())

it goes to the else condition given

So you have validation error.

Try to var_dump($model->errors);


u can use the flash message please see it…

hope it will be help


thanks to every one

guys i just removed the code and did it with simple insert query.

so i thnk now i will try to find the difference…

i hope thats one of the ways to find where i went wrong…