0

The following is the schema of my table (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)

But whenever I am trying to do execute the following query

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);

I get the following error

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

What am i doing wrong. Thanks.

0

1 Answer 1

7

You need to quote string values

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);'
)
Sign up to request clarification or add additional context in comments.

4 Comments

What Joe said - strings go in single-quotes, numbers do not. Escape your strings, don't escape your numbers.
Hey.. Yeah.. stackoverflow asks me to wait for sometime before i accept an answer.. :P
No worries, it does do that :P Cheers
the mistake is as common as missing a ; (semi-colon) in C/C++/Java and other high-level languages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.