I have this code, the purpose of which is to insert values into two tables (propects, emailsent) in mysql. I have followed the answer in Insert into 2 tables with PDO MySQL. However, I have a hard time saving the respective values in the second table. Saving to the first table (prospects) seems to work. I've search this site for answers but to no avail.
I am using PDO.
So my problem is two-fold:
- Is [A] (call to insert in tables) valid code?
- How can I make [B] valid as to save the respective values to its respective keys/column in the 2nd table (emailsent)?
if(isset($_POST['senderEmail']))
{
try
{
...
[A] $q= "INSERT INTO 'prospects'('senderName', 'senderEmail', 'offer', 'dateTimeSent')
VALUES (:senderName, :senderEmail, :offer, :dateTimeSent);
INSERT INTO 'emailsent'('call_timeSched', 'call_time', 'contactTelSched', 'contactTel', 'fileAttach', 'emailTextbox')
VALUES (:call_timeSched, :call_time, :contactTelSched, :contactTel, :fileAttach, :emailTextbox)"; // inserting into EMAILSENT table
$query = $dbh ->prepare($q);
[B] $results = $query->execute(array(
":senderName"=>$senderName,
":senderEmail"=>$senderEmail,
":offer"=>$offer,
":dateTimeSent"=>$dateTimeSent,
":call_timeSched"=>$call_timeSched,
":call_time"=>$call_time,
":contactTelSched"=>$contactTelSched,
":contactTel"=>$contactTel,
":fileAttach"=>$fileAttach,
":emailTextbox"=>$emailTextbox,
));
}
catch (PDOException $e)
{
$error = 'Error adding elements to database: ' . $e->getMessage();
include 'error.html.php';
exit();
}
exit();
}