开发者

Having trouble storing a date and time in a DATETIME column. (Using PHP and MySQL)

开发者 https://www.devze.com 2023-03-22 16:58 出处:网络
I a开发者_如何学编程m pulling a date and time from a text box in this format: yyyy-dd-mm hh:mm:ss

I a开发者_如何学编程m pulling a date and time from a text box in this format: yyyy-dd-mm hh:mm:ss

And I am trying to store this in my MySQL column set to store "DATETIME" strings. When I execute the query, the data in the table is "0000-00-00 00:00:00". I can print the string to the browser before sending it off to the SQL server and it is formatted correctly. I know I have to be missing something stupid. Why isn't my string being stored correctly on the table?

My apologies. My first time asking a coding question on a forum. haha. Here is my current code (stripped down to the basics):

    $start = "2011-24-07 18:00:00";
    $end = "2011-24-07 21:00:00";
    $SQL = "INSERT INTO table (start, end) VALUES ('$start','$end')";


The simple answer is, your date format is not correct. Print your $sql query as well on page to debug it. Then copy that query and run in mysql server. You will get exact error where the mistake is.

2011-24-07 should be 2011-07-24 :)
0

精彩评论

暂无评论...
验证码 换一张
取 消