我有这段代码,其目的是在mysql中将值插入两个表(propects,emailsent)。我已按照Insert into 2 tables with PDO MySQL中的答案。但是,我很难在第二个表中保存相应的值。保存到第一个表(前景)似乎工作。我在这个网站上搜索答案,但无济于事。
我正在使用PDO。
所以我的问题是双重的:
的
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();
}
答案 0 :(得分:0)
对我而言,我更喜欢使用它......
"INSERT INTO emailsent VALUES (:call_timeSched, :call_time, :contactTelSched, :contactTel, :fileAttach, :emailTextbox)"; // inserting into EMAILSENT table
注意U必须将所有数据库字段放在值中。