views:

32

answers:

2

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

+1  A: 

echo out your actual query so you can see what is generated.

$query = "INSERT INTO `copper` (`month`, `time`, `price`) VALUES ('$month', '$time', '$price')";   
mysql_query($query) or die(mysql_error() . '<br />Query: ' . $query);
Inigoesdr
The OP did - re-read the question
OMG Ponies
@OMG the OP did NOT, re-read the question *carefully* (`table` != `copper`)
mvds
@mdvs: People aren't allowed typos that otherwise match the SQL identically?
OMG Ponies
@OMG I'm just 99% sure that we're not seeing the query as if the OP did the `$query = "..."; mysql_query($query); echo $query;` thing as requested. This looks like a typical case where the OP doesn't disclose all we need to find the bug - so if we ask him, why would you then suggest we shouldn't? (have a look at the idiotic c++ `#ifndef` question today...)
mvds
@mvds: If you believe in this so much, why haven't you (or anyone else for that matter) voted for this answer? I prefer to give the OP the benefit of the doubt, and post comments like these... wait for it... as comments because it's not an answer to the situation.
OMG Ponies
@OMG: didn't vote because it's not an answer - I would have put this question as a comment as well, if it weren't for this "answer" which was already posted. Pending the response of the OP I did suggest a few true answers to the mystery though. If someone comes here with 100% working code, which does throw up, I think it is perfectly OK to ask for a little debugging info, just to be sure.
mvds
+1  A: 

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.

mvds