You are here: Re: Put today's date into a MySQL "date" formated field « PHP Programming Language « IT news, forums, messages
Re: Put today's date into a MySQL "date" formated field

Posted by Chris Hope on 08/03/06 21:36

walterbyrd wrote:

>
> Peter Boosten wrote:
>
>>
>> now()
>>
>
> According to php.net: "Sorry, but the function now is not in the
> online manual. "
>
> Here is the actual code:
>
> This *will* work:
>
> mysql_query("INSERT INTO inventory (item_num, location, quantity,
> date_modified) VALUES($row[0], 'FLR', $row[1], '2006-08-03')")
>
>
> This will *not* work:
>
> $today = trim(date("Y-m-d"));
> . . . .
> mysql_query("INSERT INTO inventory (item_num, location, quantity,
> date_modified) VALUES($row[0], 'FLR', $row[1], $today)")
>
> Note: the only thing in the second example that will not is the date.
> It always comes out as: "0000-00-00". I have tried the date function
> with and without the trim().
>
> I have also tried the time() function, that didn't work either.

You need quotes around the date:

mysql_query("INSERT INTO inventory (item_num, location, quantity,
date_modified) VALUES($row[0], 'FLR', $row[1], '$today')")

or realise that now() is a SQL function and do:

mysql_query("INSERT INTO inventory (item_num, location, quantity,
date_modified) VALUES($row[0], 'FLR', $row[1], now())")

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация