Search code examples
phpmysqlmysql-error-1064

mysql syntax error inserting decimal, timestamp with php


Im getting the 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 '10', '16:39:02', '292.35')' at line 1

this is the query im running in php:

mysql_query("INSERT INTO `copper` 
              (`month`, `time`, `price`) 
             VALUES 
              ('$month', '$time', '$price')") or die(mysql_error());

Here is a literal example:

INSERT INTO `table` 
  (`month`, `time`, `price`) 
VALUES 
  ('10', '16:39:02', '292.35')

this is my table setup

alt text


Solution

  • This should work as you posted it, so here's a few wild guesses:

    Are you sure $month doesn't contain a '?

    Are you sure those are actually the right kind of quotes? i.e. not the exotic stuff that comes out of word processors these days? (did you copy&paste this from the web / pdf / doc?)

    Otherwise, lose the newlines within the query, shouldn't matter but you never know.