I am new to yii and I’m having touble using the save() command. As the description states, I am getting duplicate entries of what I am saving in my database. This is the code I am running

                    $member = new Member();

                    $member->FirstName=$model->FirstName;                            //jack


                    $member->LastName=$model->LastName;                             //smith


                    $member->Gender=$model->Gender;                                     //m

                    $member->UserName=$model->UserName;                            //jackSmith

                    $member->Password=$model->Password;                               //somePassword

                    $member->DateJoined=new CDbExpression('NOW()');               //today's date


after this runs, my database has

| ID | FirstName | MiddleName | LastName | SecondLastName | Gender | UserName | Password | DateJoined | DateLeft

| 10000016 | jack | | smith | | M | jackSmith | somePassword | 2012-02-14 | NULL

| 10000015 | jack | | smith | | M | jackSmith | somePassword | 2012-02-14 | NULL

any ideas why this is happening?

can you post the whole code from your action?

Actually all you have to do is:

$model->DateJoined=new CDbExpression('NOW()'); //today's date


You don’t need to instantiate a new model (Member) to assign it the records, it doesn’t make sense.

Also, for the date added / last updated, there is a behavior provided by Yii, CTimestampBehavior, it will handle these attributes automatically for you.

check if you have ajax-validation enabled in your form (‘enableAjaxValidation’ param in CActiveForm). if yes and you do not have it properly handled in action - it will result in saving model each time user fills some field in form and it is posted to be validated…

I want to thank everyone for your input

redguy: I did have ajax-validation enabled, I just disabled it and it worked.