CDbCommand failed to execute the SQL statement: SQLSTATE[23000]:


Although the inserts go in the table correctly, I get the following exception while executing.

CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. The SQL statement executed was: insert into bus_products (bus_type_id,quantity,product_id,cat_id,subcat_id) values (:bus_type_id,:quantity,:product_id,:cat_id,:subcat_id)

the following is my controller code.

public function actionCreate()



		$model=new BusType;

         $model2=new BusProducts;

		// Uncomment the following line if AJAX validation is needed


  //Get the number of models you will be working with 

$maxRows =count($_POST['quantity']);









					 for ($i = 0; $i <= $maxRows ; $i++) 


				 $quantity = $_POST['quantity'][$i];

			 $product_id = $_POST['product_id'][$i];

			  $cat_id = $_POST['cat_id'][$i];

			   $subcat_id = $_POST['subcat_id'][$i]; 

			$sql = "insert into bus_products (bus_type_id,quantity,product_id,cat_id,subcat_id) values (:bus_type_id,:quantity,:product_id,:cat_id,:subcat_id)"; 























Can anybody please tell me why i’m getting this error and how to correct it.

Just a question, why are writing all this code, when $model->save does all and correctly?

With model->save only the last entry was getting inserted in the table. Thats y i had to write the code.

Fixed it. The for condition was worng. I should be

 for ($i = 0; $i < $maxRows ; $i++) 

and not

 for ($i = 0; $i <= $maxRows ; $i++) 


Sorry for the trouble. My bad.