0
INSERT INTO orders_total SET `title`='Discount Coupon:', `text` = '-$40.00', `value` = '40.00' WHERE `orders_id` = '15474' AND `class`='ot_coupon

It gives the following mysql error:

#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 'WHERE `orders_id` = '15474' AND `class`='ot_coupon'' at line 1

Any idea what I am doing wrong?

1
  • The INSERT INTO SET statement does not accept a WHERE clause. Commented Jun 28, 2012 at 12:37

1 Answer 1

4

INSERT statements are meant to insert new rows, now update existing ones, and a WHERE clause is therefore invalid in an INSERT. You intended to UPDATE.

UPDATE orders_total
SET 
  `title`='Discount Coupon:', 
  `text` = '-$40.00', 
  `value` = '40.00'
WHERE 
  `orders_id` = '15474' 
  AND `class`='ot_coupon'

Edit after comments:

If this was intended to be an insert rather than an update, it cannot have dependencies on conditions like orders_id = 15474. If you are inserting a new row, you need to insert those values as well.

INSERT INTO orders_total (`orders_id`, `class`, `title`, `text`, `value`) VALUES (15474, 'ot_coupon', 'Discount Coupon:', '-$40.00', '40.00');
Sign up to request clarification or add additional context in comments.

1 Comment

ah silly me, thank you, though I did mean to insert, not update

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.