0

This is my PHP code to send a date to MYSQL, but when i open the management tool of my database i get this values: 0000-00-00 00:00:00 Mysql type is set to "datetime".

...    
$dataprova = date("Y-m-d H:i:s");   
$query = "INSERT INTO oxybet(data) VALUES ('&dataprova')";
if (mysql_query($query)) { 
   echo "ok";
   echo($dataprova); 
} else { 
   echo "error"; 
} 
...

While in my page i correctly obtain: 2014-04-20 15:22:15, db show 0000-00-00 00:00:00

What is the error?

5
  • 1
    Is &dataprova a typo here or in your code as well? Commented Apr 20, 2014 at 13:28
  • &dataprova !== $dataprova Commented Apr 20, 2014 at 13:28
  • 1
    There is no error. If you want to see the error, enable MYSQL strict mode. You're right now casting some stringy '&dataprova' to a date which is correctly 0000-00-00 00:00:00 as date. So no error. - Lesson one for Mysql debugging: Check what the actual query was. Don't fly blind. Commented Apr 20, 2014 at 13:28
  • You can prevent such errors to some degree by using parametrized queries or just good old sprintf() even. Commented Apr 20, 2014 at 13:32
  • Mark baker does the trick! Commented Apr 20, 2014 at 13:50

1 Answer 1

1
$query = "INSERT INTO oxybet(data) VALUES ('&dataprova')";

Change to:

$query = "INSERT INTO oxybet(data) VALUES ('$dataprova')";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.