gpt4 book ai didi

php - 在两个表中插入值

转载 作者:行者123 更新时间:2023-11-29 13:10:06 24 4
gpt4 key购买 nike

完成表单后,我将创建一个 PDF 并将表单的一些值存储到表中。我想将表单值存储到单独的表中。我无法将代码存储到两个表中。这是我的工作代码,没有添加第二个 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));
}

这是我想要添加到另一个表的值

$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);

最佳答案

您可以只使用此查询,但使用不同的名称。像这样

  $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);

编辑:

第二个查询缺少 job_completion 的值,因此该查询将失败。

您必须计算该列的值。

关于php - 在两个表中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com