Hi im learning php and mySQL and im having issues with inserting or updating dates into MySQl.
The error i get back is usually something like:
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 ’08:17:00, 2012-07-12 08:17:00, 2012-07-12 08:17:00, 2012-07-12 08:17:00
I have 4 date entries hence the reason for 4 dates above. So the date seems to be going in but there is an issue with the time.
In my datebase im using datetime.
Here is my code, i filtered out the uneccessary stuff as everything else inserts fine if i comment out the date inserts.
$end_date = ($_POST['end_date']);
$end_date = date('Y-m-d H:i:s',strtotime($end_date));
Insert Query is simply:
mysql_query("INSERT INTO deals (end_date)
VALUES ('$end_date')")
or die(mysql_error());
Now ive literally spent hours researching this and tried a bunch of combinations without luck, one solution i did apply to an update was this which worked fine but im not sure how to apply it to an insert since i dont need the 3 days added in this scenario and im thinking better to get this date issue sorted out now while im learning.
$sql = "UPDATE deals SET deal_end_date = DATE_ADD(now(), INTERVAL $my_expiry DAY)";
Now my style of learning was to watch a 40 hour tutorial on the basics and then make a website and for each part of the website i come across a different problem, i research how to code it and learn a bit at a time. I find this so much more motivating than reading a manual.
Would appreciate any help. Because im learning maybe dumb down the code to make it more readable, i can look into stripping down the code later but i want to try and understand it better and if the solution is in more readable format that will help.
The way you compose the query elads to an invaid syntax. Try to dump the composed string instead for debugging purposes, you will find that the quotes are wrong.
WRONG:
Correct would be something like: