[英]Inserting values in two tables
On completion of a form I am creating a PDF and storing a few values of a form to a table. 完成表单后,我将创建PDF并将一些表单值存储到表中。 I would like to store the form values to a separate table. 我想将表单值存储到单独的表中。 I am having trouble getting the code to store to both tables. 我很难将代码存储到两个表中。 This is my working code without adding the second SQL query: 这是我的工作代码,没有添加第二个SQL查询:
<?php
session_start();
$errors = array();
include('connect.php');
//if($_POST['email'] == ''){
// $errors[]= 'Email cannot be empty';
//}
if( count($errors) === 0 )
{
$description = pathinfo(__FILE__, PATHINFO_FILENAME);
$filename = date('Ymdhis').".pdf";
$username = $_SESSION['username'];
$sql = "INSERT INTO documents (id, userid, description, name, date) VALUES (NULL, {$_SESSION['id']}, '{$description}' ,'{$filename}', NOW())";
$success = mysql_query($sql);
include('../MPDF/mpdf.php');
ob_start();
include('../documents/siteSubmit.php');
$html = ob_get_contents();
ob_end_clean();
ob_end_flush();
$mpdf=new mPDF();
$folder = "../userDocuments/{$_SESSION['username']}";
if(!is_dir($folder))
{
mkdir($folder, 0755, true);
}
$mpdf->writeHTML($html);
$mpdf->Output('../userDocuments/'.$_SESSION['username'].'/'.$filename);
echo json_encode(array('succes' => true));
}
else
{
echo json_encode(array('errors' => $errors));
}
and this is the values I would like to add to the other table 这是我想添加到另一个表中的值
$sql = "INSERT INTO sitesubmit (first_name, last_name, email, telephone, truck_number, truck_mileage, carrier, site_number, lat, longitude, comments, job_completion) VALUES ('first_name', 'last_name', 'email', 'telephone', 'truck_number', 'truck_mileage', 'carrier', 'site_number', 'lat', 'longitude ', 'comments')";
$success = mysql_query($sql);
you can just use this query but with different name. 您可以只使用此查询,但使用不同的名称。 like that 像那样
$sql = "INSERT INTO documents (id, userid, description, name, date) VALUES (NULL, {$_SESSION['id']}, '{$description}' ,'{$filename}', NOW())";
$success = mysql_query($sql);
$sql2 = "INSERT INTO sitesubmit (first_name, last_name, email, telephone, truck_number, truck_mileage, carrier, site_number, lat, longitude, comments, job_completion) VALUES ('first_name', 'last_name', 'email', 'telephone', 'truck_number', 'truck_mileage', 'carrier', 'site_number', 'lat', 'longitude ', 'comments','job_completion')";
$success2 = mysql_query($sql2);
EDIT: 编辑:
the second query you are missing a value for job_completion
, so this query will fail. 第二个查询您缺少job_completion
的值,因此此查询将失败。
you have to make the value of that column. 您必须确定该列的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.