MySQL 从 IN 数据和其他 table 存储产品插入

MySQL stored prod insert from IN data and other table

我在下面有一个 INSERT 语句,它取自将从 php post 请求传递的 3 个输入。下面的语句returns错误

INSERT INTO orderitems (orderId, productId, quantity, productName, price) (korderid, kproductid,kquantity, SELECT p.productName, p.price from products p WHERE p.id=kproductid)

错误是:

 The following query has failed: "CREATE PROCEDURE `CreateOrderItem`(IN `korderid` INT(8), IN `kproductid` INT(8), IN `kquantity` INT(8)) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER INSERT INTO orderitems (orderId, productId, quantity, productName, price) (korderid, kproductid,kquantity, SELECT p.productName, p.price from products p WHERE p.id=kproductid)" 

 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'korderid, kproductid,kquantity, SELECT p.productName, p.price from products p...' at line 1 ``` 

您没有提到您如何处理 post 数据。但这是如何完成的:

INSERT INTO orderitems (orderId, productId, quantity, productName, price)
SELECT :orderid, p.id, :quantity, p.productName, p.price
FROM products p
WHERE p.id = :productid

:xyz表示查询的参数。