0

I need help with a simple MySQL insert query. I have the following code:

INSERT INTO reads (location, meter, value) VALUES ('$_GET[location]', '$meter', '$value')

Which, after PHP, translates into:

INSERT INTO reads (`location`, `meter`, `value`) VALUES ('1234','1111','2505')

This query returns the following error:

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 'reads (location, meter, value) VALUES ('1234','1111','2505')' at line 1

I have gone over my syntax many times and just cant figure out what is wrong with my query. Can anyone spot it?

  • 1
    reads is the word it does not like. See the list of not allowed words: http://dev.mysql.com/doc/refman/5.6/en/keywords.html you might circumvent it by using `reads` so it uses the table name as a label instead – Norbert Jun 28 '15 at 04:16
  • If the values are stored as integers, then you don't need the single quotes around the values in your INSERT statement. – kRiZ Jun 28 '15 at 04:17
  • @anantkumarsingh That still returns the same error – blazerunner44 Jun 28 '15 at 04:18
  • @NorbertvanNobelen Thanks for the great answer. That was the solution. If you want to post your comment as an answer I will accept it. – blazerunner44 Jun 28 '15 at 04:23
  • Too short answers are demoted to comment again. Thanks anyhow :) – Norbert Jun 28 '15 at 05:07

0 Answers0