i have following code first insert is working properly and data in to database but second insert query which depends on last_insert_id() fails.I have tried to find out mistake but failed to do so?
<?php
namespace Solutions\File;
class AddUserData {
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function insert_detail($productDetails){
var_dump($productDetails);
try
{
$stmt = $this->db->prepare("INSERT INTO product_master(reg_id,category_id,sub_cat_id,product_name) VALUES(:reg_id,:category_id,:sub_cat_id,:product_name)");
$query=$this->db->prepare("INSERT INTO gy_product_detail(product_id,product_detail,"
. "product_image_back,product_image_left,product_image_name,product_image_right,"
. "product_rate,product_discount) VALUES (last_insert_id(),:product_details,"
. ":product_image1,:product_image2,:product_image3,:product_image4,"
. ":rate,:discount");
$stmt->execute(array(':reg_id'=>$productDetails['registration_id'],
':category_id'=>$productDetails['catagory_id'],
':sub_cat_id'=>$productDetails['sub_cat_id'],
':product_name'=>$productDetails['product_name']));
$query->execute(array(
':product_details'=>$productDetails['product_details'],
':product_image1'=>$productDetails['image1']['name'],
':product_image2'=>$productDetails['image2']['name'],
':product_image3'=>$productDetails['image3']['name'],
':product_image4'=>$productDetails['image4']['name'],
':rate'=>$productDetails['product_cost'],
':discount'=>$productDetails['product_discount']));
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
can anyone guide where i am wrong and point me in rigt direction,I am getting no errors however i have emabled error reporting?