【问题标题】:Update a column on rows of which another column has multiple values更新另一列具有多个值的行上的列
【发布时间】:2014-07-05 01:45:11
【问题描述】:

我遇到了这样的问题:

UPDATE `database` SET `col1` = 0 WHERE `col2` in (1,2,3,4);

以下是实际失败的查询。

Error Message:
1064: 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 '@cc3.biz, sales@allservico.com)' at line 1

SQL:

UPDATE `CubeCart_customer` SET `optIn1st` = 0 WHERE `email` in (markscarts@cc3.biz, sales@allservico.com);

我已经搜索了网络和此处,并尝试了我的代码中的几种变体来生成查询,但我无法确定我失败的地方。

我们将不胜感激。

【问题讨论】:

    标签: mysql where-in


    【解决方案1】:

    您需要在字符串值周围加上引号

    UPDATE CubeCart_customer 
    SET optIn1st = 0
    WHERE email in ('markscarts@cc3.biz', 'sales@allservico.com');
    

    【讨论】:

    • 啊,我明白了。这些值作为用逗号分隔的电子邮件地址输入到 html 页面上的文本区域中,因此我必须处理我的 $_POST['edit_group'] 字符串以插入引号并尝试。谢谢。
    • 这为 SQL 注入打开了大门。使用Prepared Statements 会更好也更容易。找个教程。这很简单,您无需再担心报价。
    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 2014-04-22
    • 1970-01-01
    相关资源
    最近更新 更多