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)

Arch
  • 517
  • 2
  • 7
  • 17

4 Answers4

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`, ....

msp
  • 3,272
  • 7
  • 37
  • 49
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);
PravinS
  • 2,640
  • 3
  • 21
  • 25
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);
kitensei
  • 2,510
  • 2
  • 42
  • 68
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);
Zelldon
  • 5,396
  • 3
  • 34
  • 46