Hi,
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()
{
$connection=Yii::app()->db;
$model=new BusType;
$model2=new BusProducts;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
//Get the number of models you will be working with
$maxRows =count($_POST['quantity']);
if(isset($_POST['BusType']))
{
$model->attributes=$_POST['BusType'];
$model2->attributes=$_POST['BusProducts'];
if($model->save())
{
$bus_type_id=$model->bus_type_id;
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)";
$command=$connection->createCommand($sql);
$command->bindParam(":quantity",$quantity,PDO::PARAM_STR);
$command->bindParam(":product_id",$product_id,PDO::PARAM_STR);
$command->bindParam(":cat_id",$cat_id,PDO::PARAM_STR);
$command->bindParam(":subcat_id",$subcat_id,PDO::PARAM_STR);
$command->bindParam(":bus_type_id",$bus_type_id,PDO::PARAM_STR);
$command->execute();
$model2->save();
}
$this->redirect(array('view','id'=>$model->bus_type_id));
}
}
$this->render('create',array(
'model'=>$model,
'model2'=>$model2,
));
}
Can anybody please tell me why i’m getting this error and how to correct it.