I am trying to insert data to two tables using the id for the first table. I have tried several possibilities but none seem to work. Please see below for the current method I am using. It is inserting to the first table but not the second. Plus there isn't any error telling me what I did wrong.
If anyone can tell me where I am going wrong that would be great.
public function addContact($cnt_fname,$cnt_lname,$cnt_email,$cnt_phone,$cnt_type,$cnt_company,$cnt_web,$cnt_add1,$cnt_add2,$cnt_city,$cnt_state,$cnt_post,$cnt_country,$cnt_status) {
try
{
$stmt = $this->conn->prepare("
START TRANSACTION;
INSERT INTO LeadContact(lead_fname,lead_lname,lead_email,lead_phone,lead_type,lead_company,lead_add1,lead_add2,lead_city,lead_state,lead_post,lead_country,lead_status)
VALUES(:cnt_fname,:cnt_lname,:cnt_email,:cnt_phone,:cnt_type,:cnt_company,:cnt_add1,:cnt_add2,:cnt_city,:cnt_state,:cnt_post,:cnt_country,:cnt_status);
INSERT INTO LeadCompany(company_phone,company_type,company_name,company_website,company_add1,company_add2,company_city,company_state,company_post,company_country,company_status,company_contact)
VALUES(:cnt_phone,cnt_type,:cnt_company,:cnt_web,:cnt_add1,:cnt_add2,:cnt_city,:cnt_state,:cnt_post,:cnt_country,:cnt_status,last_insert_id());
COMMIT;
");
$stmt->bindparam(":cnt_fname", $cnt_fname);
$stmt->bindparam(":cnt_lname", $cnt_lname);
$stmt->bindparam(":cnt_email", $cnt_email);
$stmt->bindparam(":cnt_phone", $cnt_phone);
$stmt->bindparam(":cnt_type", $cnt_type);
$stmt->bindparam(":cnt_company", $cnt_company);
$stmt->bindparam(":cnt_add1", $cnt_add1);
$stmt->bindparam(":cnt_add2", $cnt_add2);
$stmt->bindparam(":cnt_city", $cnt_city);
$stmt->bindparam(":cnt_state", $cnt_state);
$stmt->bindparam(":cnt_post", $cnt_post);
$stmt->bindparam(":cnt_country", $cnt_country);
$stmt->bindparam(":cnt_status", $cnt_status);
$stmt->bindparam(":cnt_web", $cnt_web);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
The suggested duplicate is not the same question as I am trying to use the last_insert_id() function.