此声明有什么问题,因为customers表只有一条记录
INSERT INTO CART (Cartid,custid,Pid)
VALUES ('2',SELECT(custid from CUSTOMERS), SELECT (Pid from Products where Pname ='shirts'))
答案 0 :(得分:0)
正确的语法是:
INSERT INTO CART (Cartid, custid, Pid)
VALUES (2,
(SELECT custid FROM CUSTOMERS LIMIT 1),
(SELECT Pid FROM Products WHERE Pname = 'shirts' LIMIT 1)
);
你的括号在错误的地方。
注意:
LIMIT
只是为了强制返回一行。'2'
周围的单引号,因为ID通常是数字。答案 1 :(得分:0)
确保购物车表ID是主键和auto_increment。获取客户ID并存储在变量中。你可以尝试类似这样的东西
INSERT INTO CART (Cartid,custid,Pid) VALUES ('', SELECT custid from CUSTOMERS WHERE custid = '$customer_id'),(SELECT Pid FROM Products WHERE Pname = 'shirts' LIMIT 1));