douxia9826 2016-07-28 15:22
浏览 45
已采纳

SQL语法错误,我找不到错误[重复]

This question already has an answer here:

I can't find the error after 3 hours trying. Can someone help my ?

this is my query =

$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;";

This is when I echo my query =

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

Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ProductBarcode = ,ProductPakking = ,ProductPresent = ,ProductMinimuim = ' at line 1

</div>
  • 写回答

1条回答 默认 最新

  • duanhao5038 2016-07-28 15:25
    关注

    I'm assuming $ProductName is not an integer, so you'd need to include that in quotes here:

    WHERE `ProductName` = '" . $ProductName . "'
    

    Also, please note, you SHOULD NOT be concatenating variables into a string like that. Please see this post for info about how bad this is.

    An updated SQL statement PLEASE DON'T USE THIS, BIND VARIABLES INSTEAD:

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 unity安卓打包出现问题
  • ¥15 爱快路由器端口更改错误导致无法访问
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
  • ¥15 fluent设置了自动保存后,会有几个时间点不保存
  • ¥20 激光照射到四象线探测器,通过液晶屏显示X、Y值
  • ¥50 数据库开发问题求解答
  • ¥15 安装anaconda时报错
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部