|
Posted by Rik on 08/06/06 18:20
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.
>
> 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?
Easiest way: let the database itself handle it, and leave the timestamp
field out of the query:
ALTER TABLE `lounge` CHANGE `add_date` TIMESTAMP NOT NULL DEFAULT
CURRENT_TIMESTAMP
optionally with:
ON UPDATE CURRENT_TIMESTAMP
$db->query('INSERT INTO lounge (isbn, artist_name, album_title,
release_date, description, price)
VALUES (?,?,?,?,?,?)',
array($_POST['isbn'],
$_POST['artist_name'],
$_POST['album_title'],
$_POST['release_date'],
$_POST['description'],
$_POST['price']));
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|