|
Posted by IchBin on 08/06/06 19:14
mpar612@gmail.com wrote:
> IchBin wrote:
>> mpar612@gmail.com wrote:
>>> Hi everyone,
>>>
>>> Pretty new to the forums, PHP and MySQL here. I am having an issue
>>> inserting the current date and time into a MySQL database using PHP.
>>>
>>> My table in MySQL is setup with add_date as date not null.
>>>
>>> Here is my query:
>>> $db->query('INSERT INTO lounge (isbn, artist_name, album_title,
>>> release_date, add_date, description, price)
>>> VALUES (?,?,?,?,?,?)',
>>> array($_POST['isbn'], $_POST['artist_name'],
>>> $_POST['album_title'], $_POST['release_date'], curdate(),
>>> $_POST['description'], $_POST['price']));
>>>
>>> My issue is with automatically entering the current date and time into
>>> the add_date field of the database. I did some searching and tried the
>>> curdate() function in MySQL and that did not work. This is not a date
>>> that is input by the user. I would like the date to be automatically
>>> added to the database without it being known to the user.
>>>
>>> Does anyone have any thoughts on how this is done?
>>>
>>> Thanks!
>>>
>> You can define your DB 'add_date' column as a timestamp with the
>> following format:
>>
>> add_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
>> ON UPDATE CURRENT_TIMESTAMP
>>
>> This way you could eliminate any reference to 'add_date' in you code but
>> have it automatically inserted on a insert or update to that DB row.
>>
>> Look at this link
>> http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html
>>
>> Thanks in Advance...
>> IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
>> __________________________________________________________________________
>>
>> 'If there is one, Knowledge is the "Fountain of Youth"'
>> -William E. Taylor, Regular Guy (1952-)
>
> Thanks! This works great! Is there an easy way to retrieve this date
> and reformat it using PHP?
> Thanks again!
>
Since you multi-posted and not crossed posted another person answered
you question in another newsgroup.
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Navigation:
[Reply to this message]
|