"insert"命令时出现 MySQL 错误

标签 mysql insert syntax-error

以下是我的表的架构(name->add_to_cart);

add_to_cart_id   int(10) PK
created_date     timestamp
ip_address       varchar(17)
customer_id      int(11)
session_id       varchar(1024)
brand_id           int(11)
product_id       int(11)
sales_event_id   int(11)
quantity         int(11)
referer          varchar(1024)
user_agent       varchar(1024)

但是每当我尝试执行以下查询时

INSERT INTO `add_to_cart` (add_to_cart_id,created_date,ip_address,customer_id,session_id,sku_id,product_id,sales_event_id,quantity,referer,user_agent) VALUES (1,2011-02-24 20:40:34,66.65.135.89,70154,qbk5r0rg9sl2ndiimquvnsab46,83791,308933,10105,2,https://www.onekingslane.com/product/10105/308933,Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML);

出现以下错误

ERROR 1064 (42000): 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 '20:40:34,66.65.135.89,70154,qbk5r0rg9sl2ndiimquvnsab46,83791,308933,10105,2,http' at line 1 ERROR 1064 (42000): 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 'U' at line 1 ERROR 1064 (42000): 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 'Intel Mac OS X 10_6_5' at line 1 ERROR 1064 (42000): 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 'en-us) AppleWebKit/533.19.4 (KHTML)' at line 1

我做错了什么。 谢谢。

最佳答案

你需要引用字符串值

INSERT INTO `add_to_cart`
(
    add_to_cart_id,
    created_date,
    ip_address,
    customer_id,
    session_id,
    sku_id,
    product_id,
    sales_event_id,
    quantity,
    referer,
    user_agent
)
VALUES
(
    1,
    '2011-02-24 20:40:34',
    '66.65.135.89',
    70154,
    'qbk5r0rg9sl2ndiimquvnsab46',
    83791,
    308933,
    10105,
    2,
    'https://www.onekingslane.com/product/10105/308933,Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.19.4 (KHTML);'
)

关于 "insert"命令时出现 MySQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7423431/

相关文章:

php - 在mysql中获取24小时格式的日期范围

mysql - 将 Mysql 表复制到 Oracle 时非法使用 LONG 数据类型

postgresql - 向表中插入数据的最快方法

c++ - 将唯一数据推送到 vector 中

java - 编译错误,看不懂

node.js - 在node.js中发送HTTP响应

syntax - VHDL If语句语法错误

php - 如何使用 MySQL 结果集组合、分页和排序外部 API

php - 如何将 PHP 数组保存到 MySQL 数据库,以便我可以搜索数据库中的数组?

mysql - 如何在MySQL插入中进行选择