0

I Use simple sql query to save some date to database.

mysql column:

current_date` date DEFAULT NULL,

But when executed query show Error:

insert into
  computers
  (computer_name, current_date, ip_address, user_id)
values
  ('Default_22', '2012-01-01', null, 37);

[2016-03-22 12:21:46] [42000][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 'current_date, ip_address, user_id)

1
  • current_date is reserve word Commented Mar 22, 2016 at 10:51

4 Answers 4

1

current_date is a mysql function, you can't have it as columns alias in your insert into query;

try escaping your column names

insert into computers (`computer_name`, `current_date`, ....

Sign up to request clarification or add additional context in comments.

Comments

0

"current_date" is reserved in MySQL, so use (`) character to enclose field names

Use this

INSERT INTO computers
  (`computer_name`, `current_date`, `ip_address`, `user_id`)
VALUES
  ('Default_22', '2012-01-01', null, 37);

Comments

0

current_date is a mysql reserved keyword, try: select current_date, you can either rename your columns, or escape your query like this:

insert into
  computers
  (`computer_name`, `current_date`, `ip_address`, `user_id`)
values
  ('Default_22', '2012-01-01', null, 37);

Comments

0

As you see in the mysql documentation http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_current-date

current_date is a function in MySQL, which returns the current date. So either change the column name or escape the column name in the insert into with backticks.

insert into
  computers
  (`computer_name`, `current_date`, `ip_address`, `user_id`)
values
  ('Default_22', '2012-01-01', null, 37);

3 Comments

you should not use simple quotes for column names: see this
its should be `` not ''
Thanks i changed it.

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.