Store current date to MySQL table via PHP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dt
Forum Newbie
Posts: 4
Joined: Mon Mar 06, 2006 12:20 pm

Store current date to MySQL table via PHP

Post by dt »

Sorry for the novice question...

I have a form and a PHP script that takes the input of that form and inserts a line into an MySQL table. All works fine except I am having trouble getting the current date value added. In the PHP code I have something like the following:
$today=date("Y-m-d");

And I have tried a variet of formats such as:
$today=date("m/d/y");

If I echo the variable $today, it is what I would expect (i.e. 2006-03-26 in the first case, 03/26/2006 in the second).

In my PHP table I have tried having the column be of type date, datetime, and char (I would prefer date or datetime), but regardless I cannot get the value stored in $today inserted in a date (or date-like character) format into the table. If the column is of type date or datetime it allways appears as 0000-00-00, never the actual value from $today. If I change it to type char I get some strange decimal number (as if it is performing the math of month/day/year).

Any help with what I am missing (probably something obvious) would be appreciated.

Thanks,

Daryl
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

You can simply use NOW() (MySQL function) to insert current date into any row.
insert into tablename (date) values (NOW())
[/quote]
dt
Forum Newbie
Posts: 4
Joined: Mon Mar 06, 2006 12:20 pm

Thanks

Post by dt »

Thanks gambler, I figured I was over complicating the issue...
Post Reply