【发布时间】:2013-12-13 05:58:26
【问题描述】:
我有这段代码,其目的是将值插入到 mysql 中的两个表(propects,emailsent)中。我已按照Insert into 2 tables with PDO MySQL 中的答案进行操作。但是,我很难将各自的值保存在第二个表中。保存到第一个表(前景)似乎有效。我已经在这个网站上搜索答案,但无济于事。
我正在使用 PDO。
所以我的问题有两个:
- [A](调用插入表格)是有效代码吗?
- 如何使 [B] 有效以将相应的值保存到第二个表(电子邮件发送)中的相应键/列?
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();
}
【问题讨论】: