1

I have sql code for inser test value to db:

INSERT INTO log (from, value) VALUES ('ABC', 'DEF')

I have table log:

from | value

from and value are varchar(255).

When I run my code I a getting 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 'from, value) VALUES ('ABC', 'DEF')' at line 1

I don't know why, can you give me advice? I have a syntax error in code? Or what?

2
  • 2
    from is a reserved word in SQL. It is a really bad name for a column. Change the name. I'm voting to close, because from is an obvious reserved word. Commented Apr 1, 2017 at 11:42
  • Following the other comments you got, look carefully at your post and you may notice the reserved words have a unique blue color. If the color of "from" is different than that of "value", it should raise a suspicion. Commented Apr 1, 2017 at 11:51

2 Answers 2

2

fromis a MySQL keyword. Rename the column if you can.

ALTER TABLE `log`
CHANGE COLUMN `from` `something_else` VARCHAR(255)

If you can't, use backticks around the column names.

INSERT INTO `log` (`from`, `value`) VALUES ('ABC', 'DEF')
Sign up to request clarification or add additional context in comments.

Comments

1

"from" is a reserved key word in SQL. Its better to change the column name. If you don't want to change the column name then use following query. it works fine. The Query looks like.

insert into log(`from`,value) values ('abc','def'). I hope that helps you!!

Comments

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.