unexpected multiple record creation in shared hosting

Hi all,

I hosted my yii powered website on network solutions shared hosting, I have 4 models and 3 of them working great. But I am facing problem with one model that is after pressing the create button, record get created twice and some time thrice with different id but same data. The model was working fine on local host.

Immidiate help required.

Thnx

can you post a code…which you have written to create a record.so, that i can try to help you.

here is my controller code


<?php


........


	public function actionCreate()

	{

		$model=new Deposit;


		// Uncomment the following line if AJAX validation is needed

		 $this->performAjaxValidation($model);


		if(isset($_POST['Deposit']))

		{

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

			if($model->save())

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

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}


				

and my model code


<?php

.....

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'u' => array(self::BELONGS_TO, 'User', 'uid'),

		);

	}


.......


	protected function afterSave()

	{

		$bal = UserBalance::model()->findByPk(Yii::app()->user->id);

		if ($bal !== null)

		{	

			if ($this->isNewRecord)

			{

				$bal->balance = ($bal->balance + $this->amount);

				$bal->save(false);

			}

		}

		parent::afterSave();

	} 

}

:(…its to messy to read this whole code for this problem…kindly post a code snippet of action which is creating a active record from your controller file.

And after reviewing your code from model file… i got that you are using a afterSave method




protected function afterSave()

	{

		$bal = UserBalance::model()->findByPk(Yii::app()->user->id);

		if ($bal !== null)

		{	

			if ($this->isNewRecord)

			{

				$bal->balance = ($bal->balance + $this->amount);

				$bal->save(false);

			}

		}

		parent::afterSave();

	} 



could you please tell me why you are using this method.Might be a problem with this method as i am assuming in the first look.

please check your method definition again for afterSave method.

and post your feedback again.

i am using afterSave() method to update balance amount if user deposits something… it is also called many times when create method of deposit is called… their is no mistake in aftersave method… i am not getting why the create action of deposit model get called many times?? :(

Add a model scenario before assigning a Post value as a model attribute.


$model->scenario = 'create';

in the action create after importing a model.

let it try and revert back with your feedback.

hello,

i think create action will make it twice with id : 1,2 etc …

it maybe delay on connection or double click. can you make delay time to that create from same creator ? lets say 30 sec, so then he will cant create twice if he double click by mistake due to delay on connection.

best regards

hey rahul.vit09m,

yes i am also agreed with Dr. x comment.please also try to debug a $_POST data that which data array you are getting everytime and please check this also with a help o firebug.so might be you can track the issue very well.

Guys thanks for your help, I tried all possible debugging and finally found that it happened due to a bug in my code i.e. i put the same id for deposit form and user form.

I changed the id for deposit form and got correct results :)