1 回答
TA贡献1815条经验 获得超10个赞
没有“多重插入”之类的东西。每个插入必须单独执行。特别是如果您需要从每个查询中插入 id。
所有插入查询都必须使用准备好的语句来执行。
这是您正确编写的代码
$sql = "INSERT INTO `product` (`product_id`, `barcode`, `delete`, `id_list_name`) VALUES (NULL, ?, '0', ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $barcode,$listnameid);
$product_id = $conn->insert_id;
$sql = "INSERT INTO `loan` (`loan_id`, `date`, `Quantity`, `delete`, `id_user`) VALUES (NULL, CURDATE(), '1', '0', ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $userid);
$loan_id = $conn->insert_id;
$sql = "INSERT INTO `import` (`import_id`, `id_product`, `date`, `delete`, `date delete`, `id_user`, `id_loan`) VALUES (NULL, ?, CURDATE(), '0', '', ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sss", $product_id, $userid, $loan_id;);
$import_id = $conn->insert_id;
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报