A Question
Moderator: General Moderators
A Question
Sirs, how do you save a time data to the database?
Or specifically, how do I save the time data to a mySQL database the moment I press a button?
Or specifically, how do I save the time data to a mySQL database the moment I press a button?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: A Question
Usually you would create a DATETIME field and set it to NOW() in your INSERT or UPDATE.
(#10850)
Re: A Question
How do you do that exactly, coding the button? I am at a loss how to use Post while using the Now() fcn.
Re: A Question
In whatever script that updates or inserts your record, include an additional field that sets the current date using the now() function.
$sql = "INSERT INTO table (field1, field2, ..., current_date) VALUES ('value1', 'value2', ..., 'now()')";
If you need to save the date/time in a particular format, you can also use date(), but how the timestamp is displayed can always be changed when you output the data.
$sql = "INSERT INTO table (field1, field2, ..., current_date) VALUES ('value1', 'value2', ..., 'now()')";
If you need to save the date/time in a particular format, you can also use date(), but how the timestamp is displayed can always be changed when you output the data.
Re: A Question
Wanger, thanks for that. But it does not seem to be posting the values of the now() / date() to the date field that I have.
My date field is in DATETIME.
EDIT| I even did it this way:
My date field is in DATETIME.
Code: Select all
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]', 'date()' )";
Code: Select all
$deight=date("Y-m-d H:i:s");
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]',$deight)";Re: A Question
Code: Select all
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]', 'date()' )";Re: A Question
Here it is:mikosiko wrote:post the code that you are using to execute the $sql sentence ....Code: Select all
$sql="INSERT INTO Printing (name, page, date) VALUES ('$_POST[name]','$_POST[page]', 'date()' )";
Code: Select all
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}Re: A Question
Although you were able to get help with your question, from now on please use a more descriptive thread title when posting questions in the forums. I personally will not click on threads which have such vague titles except to tell the poster to make their title more specific. When people are browsing the forums, all they have to go by is your thread title, so make it easy on them to help you and give them a descriptive title. Thanks!
Re: A Question
Duly noted, Luke. Thanks for that. 