Some Problem By Inserting In Database.

I have model which handle my file uploading. everything ok.

but when it run the save() method, in the datebase insert 2 record and then insert my uploaded file name record.

what is the problem?:unsure:

this is my controller action:

public function actionCreate() {

    	$model = new Picture;

    	if (isset($_POST['Picture'])) {

        	$rnd = rand(0, 9999);

        	$model->attributes = $_POST['Picture'];

        	$uploadFile = CUploadedFile::getInstance($model, 'address');


        	$model->address = "{$rnd}-{$uploadFile}";


        	if ($model->save()) {

                	$uploadFile->saveAs(Yii::app()->basePath . '/../upload/' . "{$rnd}-{$uploadFile}");

            	//$this->redirect(array('view', 'id' => $model->id));



    	$this->render('create', array('model' => $model, ));


Do you have enabled the ajax validation in your form? If so, you have to handle the ajax validation request in the controller action, otherwise $model->save() could be called twice.

No, in my controller there isn’t any ajax validation.

No, I mean in the view. Something like:

    $form = $this->beginWidget('CActiveForm',


            'id' => 'photo-form',

            'enableAjaxValidation' => true, // !!




ohh. Thank`s very much. that was it.:huh: