-1

I'm getting a syntax error for a very simple SQL query I'm trying to do:

INSERT INTO history (character, type, amount, extra)
VALUES('$character', '$type', '$amount', '$extra')

Here's the way the table is set up:

SQL table

The full error it gives me is the following:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'character, type, amount, extra) VALUES('Ellie', 'Gift', '-200', 'to Rick')' at line 1

I've already checked and double checked the usual mistakes like the table name, spelling errors, column order etc, but I'm clueless as to what it's still detecting, and hoping one of you can help me out...

diiN__________
  • 7,393
  • 6
  • 42
  • 69
iEllya
  • 3
  • 1

1 Answers1

2

character is a reserved keyword in mysql. Rename the column or use backticks for escaping it.

INSERT INTO history (`character`, type, amount, extra)
VALUES('$character', '$type', $amount, '$extra')
Jens
  • 67,715
  • 15
  • 98
  • 113
  • Actually, only `CHARACTER` is reserved, not `TYPE`, so only the former needs to be ticked. I did do an edit earlier to add "reserved", so you may want to readjust respectively ;-) – Funk Forty Niner Aug 30 '17 at 12:38
  • Awesome, I simply renamed the column to characterName instead of just character, and it works! Thank you all very much! – iEllya Aug 30 '17 at 12:47