尝试3小时后我找不到错误。有人可以帮我吗?
这是我的查询=
$query = "INSERT INTO `card`(ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid) SELECT * FROM (SELECT '" . $ProductName . "','" . $ProductBarcode . "','" . $ProductPakking . "','" . $ProductPresent . "','" . $ProductMinimuim . "','" . $FotoUrl . "','" . $DBid ."') AS tmp WHERE NOT EXISTS (SELECT name FROM `card` WHERE `ProductName` = " . $ProductName . ",`ProductBarcode` = " . $ProductBarcode . ",`ProductPakking` = " . $ProductPakking . ",`ProductPresent` = " . $ProductPresent . ",`ProductMinimuim` = " . $ProductMinimuim . ",`FotoUrl` = " . $FotoUrl . ",`DBid` = " . $DBid ." ) LIMIT 1;";
这是我回显我的查询=
INSERT INTO `card`(ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid)
SELECT * FROM (
SELECT 'brood','8717333541583','zak','-1937','11','img/img.svg','3') AS tmp
WHERE NOT EXISTS (
SELECT name FROM `card` WHERE
`ProductName` = 'brood',
`ProductBarcode` = '8717333541583',
`ProductPakking` = 'zak',
`ProductPresent` = '-1937',
`ProductMinimuim` = '11',
`FotoUrl` = 'img/img.svg',
`DBid` = '3' )
) LIMIT 1
错误 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行“
ProductBarcode
=,ProductPakking
=,ProductPresent
=,ProductMinimuim
='附近使用正确的语法< / p>
答案 0 :(得分:3)
我假设$ProductName
不是整数,因此您需要在引号中包含它:
WHERE `ProductName` = '" . $ProductName . "'
另外,请注意,您不应该将变量连接成类似的字符串。有关这有多糟糕的信息,请参阅this post。
更新后的SQL语句请不要使用此内容,绑定变量:
INSERT INTO `card`(ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid)
SELECT * FROM (
SELECT '" . $ProductName . "','" . $ProductBarcode . "','" . $ProductPakking . "','" . $ProductPresent . "','" . $ProductMinimuim . "','" . $FotoUrl . "','" . $DBid ."') AS tmp
WHERE NOT EXISTS (
SELECT ProductName FROM `card` WHERE
`ProductName` = '" . $ProductName . "' AND
`ProductBarcode` = '" . $ProductBarcode . "' AND
`ProductPakking` = '" . $ProductPakking . "' AND
`ProductPresent` = '" . $ProductPresent . "' AND
`ProductMinimuim` = '" . $ProductMinimuim . "' AND
`FotoUrl` = '" . $FotoUrl . "' AND
`DBid` = '" . $DBid ."'
) LIMIT 1;