Forum Moderators: coopster

Message Too Old, No Replies

mysql timestamp not working

enters 00000000000000

         

HelenDev

12:28 pm on Oct 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I enter an item directly in to my db, it enters the correct timestamp, but I have a content management system which updates the db through a browser. This works except for the timestamp, in which it enters 00000000000000. Does anyone have any ideas how to fix this?

ergophobe

3:06 pm on Oct 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you know how the CMS enters the date?

Did the CMS create the database tables or did you?

Some possible problems could be things like the CMS uses a unix-style timestamp, which will be an invalid MySQL timestamp and would probably just give you zeros like that (not sure). The easy solution in that case would be to change the column type to some type of numeric type ( e.g. INT) or even a string, since it will get returned as a string from MySQL anyway.

Since this is something that's supposed to work on update, I'm assuming that it is using something like "now()" to set the time or "time()" if it's a unix timestamp. If that's not true and you're actually entering the time onscreen in some way (manually or with drop-down menus), it may be sending the wrong format and mysql chokes. If that's the case, echo out your $_POST vars and see how the date is being sent.

Tom

HelenDev

1:10 pm on Oct 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cheers Tom,

The cms is one that I built (not all that sophisticated mind!).

I haven't got the code to hand, but I think it's just entering '' or 'NULL'. Should I be putting now()instead? I did read somewhere that if I put in a null value the timestamp would somehow overwrite it with a default value of the current timestamp, so I think that's why I built it that way.

timster

2:53 pm on Oct 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it's just entering '' or 'NULL'.

Just leave the timestamp column out of the INSERT or UPDATE statement entirely, and the timestamp should work properly.

HelenDev

4:44 pm on Oct 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That works a treat, thanks :)