1

datatimepicker is working fine but can't insert the date.time into the database, always get Syntax error or access violation: 1064 error. " note that datetimepicker format is similar to this 06-27-2016 12:00 AM."

<div class='input-group date' id='datetimepicker1'>
             <input type='text' class="form-control" id="datepicker" name="datepicker"/>
             <span class="input-group-addon">
             <span class="glyphicon glyphicon-calendar"></span>
             </span>
         </div>

query

$sql = "INSERT INTO news(`newsdate`,`title`)VALUES (".$_POST["datepicker"]."',".$_POST["title"]."')";
Aboud Jouda
  • 107
  • 1
  • 9
  • Your SQL is invalid and wide open to SQL injections. Strings need to be quoted and you should never have user input in a SQL query. Why are you only putting closing quotes on the strings `"',"`? Also `06-27-2016 12:00 AM` is not a mysql datetime format, you should be using `datetime` data type so you can use the date and time functions in the future. – chris85 Jun 27 '16 at 02:03
  • Possible duplicate of [How can I prevent SQL-injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – chris85 Jun 27 '16 at 02:05
  • i'm not looking for preventing sql injection i just want to know how to deal with this problem i'm trying to learn that's all – Aboud Jouda Jun 27 '16 at 02:13
  • 2
    It is the same problem though. You fix the injection issue and the code will work (because the driver will handle all the quoting and escaping that is needed). If you reallly don't want to fix the injection issue output `$sql` and you should see the issue. – chris85 Jun 27 '16 at 02:13

0 Answers0