如何用php查询mysql命令?这个语法正确吗?

nhjlsmyf  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(290)

我正在尝试运行以下代码:

$query = "INSERT INTO products_configurations (product_id, cuts) 
VALUES (SELECT pro.id FROM pages AS p
JOIN products AS pro ON pro.page_id = p.id WHERE p.id = $pageid, $combination)";

但我犯了个错误。
有关详细信息,变量值为:

$pageid = 21605
$combination = "40 - Red"

这是我遇到的错误(为了便于阅读,请使用虚线):
sql语法有错误;
请查看与mysql服务器版本对应的手册,以获得正确的语法
'从页面中选择pro.id作为p
在pro.page\u id=p.id中将产品作为pro连接,其中p'位于第1行
编辑:
我使用此代码是为了插入 product_id 另一个表中的一个值,并且它可以工作:

$query = "INSERT INTO products_configurations (product_id)
(SELECT pro.id FROM pages AS p JOIN products AS pro ON pro.page_id = p.id WHERE p.id = $pageid)";
c8ib6hqw

c8ib6hqw1#

$query = "INSERT INTO products_configurations (product_id, cuts) 
((SELECT pro.id FROM pages AS p
 JOIN products AS pro ON pro.page_id = p.id WHERE p.id = $pageid), 
 \"$combination\");";

不要在insert by select查询中使用值;

wnavrhmk

wnavrhmk2#

$query = "INSERT INTO products_configurations (product_id, cuts) 
VALUES ((SELECT pro.id FROM pages AS p
JOIN products AS pro ON pro.page_id = p.id WHERE p.id = $pageid), \"$combination\");";

看看这个

相关问题