php - 第一条语句执行,但第二条语句不执行
问题描述
我对 PHP 和 MySQL 比较陌生(一年级 comp sci 学生),我正在锁定期间的空闲时间从事一个项目,以保持自己忙碌。将新产品插入产品表后,如何插入复合键 (wishlist_product)?第一条语句执行,但是第二条语句没有执行,我没有收到错误
try {
//Begin the transaction
$connect->beginTransaction();
//Step 1:- Prepare the statement
$stmt = $connect->prepare("INSERT INTO product(product.productURL, product.productName, product.productCost, product.productQuantity)
VALUES(:productURL, :productName, :productCost, :wishlistName);");
//Step 2:- Bind the values with the variable
$stmt->bindparam(":productURL", $productURL);
$stmt->bindparam(":productName", $productName);
$stmt->bindparam(":productCost", $productCost);
$stmt->bindparam(":wishlistName", $listNameURL);
//Step 3:- Execute the statement
$stmt->execute();
//Get the ID of the product inserted
$insertID = $connect->lastInsertId();
//Step 1:- Prepare the statement
$stmt = $connect ->prepare("INSERT INTO wishlist_product(wishlistID, productID)
SELECT wishlistID, productID
FROM wishlist, product
WHERE wishlist.wishlistName=':wishlistName'
AND product.productID=':productID';");
//Step 2:- Bind the values with a variable
$stmt->bindParam(":wishlistName", $listNameURL);
$stmt->bindParam(":productID", $insertID);
//Step 3:- Execute the statement
$stmt->execute();
//Commit the changes
$connect->commit();
}
catch(PDOException $e) {
//Something went wrong, rollback DB
$connect->rollback();
throw $e;
die();
}
解决方案
推荐阅读
- node.js - npm install bootstrap@4.0.0 命令给出 ENETUNREACH 错误
- python - 如何编码分类预测值?
- java - 根据字符串的不同模式拆分字符串
- json - 我有嵌套的列表对象,称为 JSON 中的剧集,那么如何根据 id 父对象而不是位置对象获取剧集列表?
- python - 数据框中的字符串编辑不使用 .replace 代码生效
- django - 如何使用 django.utils.timezone 库将日期时间从特定时区转换为其 UTC 版本?
- python - 将一个大的 numpy 数组转换为字符串
- mysql - Mysql更新多行
- angular - Angular 8 - 没有访问控制允许请求的资源上存在 Origin 标头?
- django - 删除按钮表单标签导致换行