0

I am trying to INSERT time which is in format "Tue, 14 Jan 2014 19:56:09 +0530" using query

   INSERT INTO monitor (Date, Name ) VALUES ('$Date','$Name') ";
   mysql_query($query) or die ("query failed");

This query execute without any error but when I look into values inserted it was found that value of time in different other than what is in $Date , value inserted is "0000-00-00 00:00:00" other than "Tue, 14 Jan 2014 19:56:09 +0530". Is any their anything I am doing wrong.

SAT
  • 647
  • 1
  • 12
  • 23
Deepak
  • 414
  • 5
  • 16

1 Answers1

5
  1. You need to format it using STR_TO_DATE() inline with your INSERT. For example, SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y'); ... Use the specifiers in this table
  2. Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.
  3. You have no error handlers
Community
  • 1
  • 1
Kermit
  • 33,827
  • 13
  • 85
  • 121
  • @Alexxus Are you implying OP should continue to use `mysql_` functions? – Kermit Jan 14 '14 at 15:09
  • True @Alexxus, but it's excellent advice. It's standard practice here on StackOverflow to warn people when they're opening themselves up for SQL Injection trouble, which can be a career ender. – Ed Gibbs Jan 14 '14 at 15:12
  • No, but your points 2 and 3 have nothing in common with the solution of the problem. They are only a warning/note and shouldn't be numbered in my opinion – Alexxus Jan 14 '14 at 15:13
  • 2
    @Alexxus I'll make sure not to use lists when you're on SO reading my answers. – Kermit Jan 14 '14 at 15:16