Question

I have tried to find out what's wrong.

The table is conditions_loop. One column is condition_id, and the other one is a datetime type.

the code is this

$dt = date("Y-m-d H:i:s");

mysql_query("INSERT INTO conditions_loop (condition_id, date) VALUES ($latest_condition, $dt)") or die(mysql_error());  

$latest_condition is a 1 digit integer.

The error says 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 '13:12:14)' at line 1

I tried everything, but it's something I don't know. Thanks for reading.

Was it helpful?

Solution

You should quote the date value:

mysql_query("INSERT INTO `conditions_loop` (`condition_id`, `date`) 
         VALUES ('$latest_condition', '$dt')") or die(mysql_error());  

And while you're at it, quote the table/field names as well, using backticks (`)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top