Reputation: 105
Using a form I am adding some basic fields to my table.
I also want to add the current date the data from the form is posted.
Any suggestions on how to do this would be appreciated.
Thanks.
$sql="INSERT INTO Experiments(Author, Title, Description)
VALUES
('$_POST[author]','$_POST[title]','$_POST[description]')";
if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
header('Location: http://example.com');
Upvotes: 1
Views: 51
Reputation: 11588
You don't need to enter it with PHP. Add a TIMESTAMP
column to your table and set its default value to CURRENT_TIMESTAMP
:
ALTER TABLE `Experiments` ADD COLUMN `time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
Oh, and please sanitize your data entry!
Upvotes: 1
Reputation: 5103
$sql="INSERT INTO Experiments(Author, Title, Description, DATE) VALUES ('$_POST[author]','$_POST[title]','$_POST[description]', NOW())";
Upvotes: 0