Page 1 of 1
A Question
Posted: Wed Mar 17, 2010 9:35 pm
by Tralalah
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?
Re: A Question
Posted: Thu Mar 18, 2010 2:18 am
by Christopher
Usually you would create a DATETIME field and set it to NOW() in your INSERT or UPDATE.
Re: A Question
Posted: Thu Mar 18, 2010 6:39 am
by Tralalah
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
Posted: Thu Mar 18, 2010 8:27 am
by wanger220
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.
Re: A Question
Posted: Thu Mar 18, 2010 7:15 pm
by Tralalah
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.
Code: Select all
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]', 'date()' )";
EDIT| I even did it this way:
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
Posted: Thu Mar 18, 2010 7:44 pm
by mikosiko
Code: Select all
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]', 'date()' )";
post the code that you are using to execute the $sql sentence ....
Re: A Question
Posted: Thu Mar 18, 2010 8:12 pm
by Tralalah
mikosiko wrote:Code: Select all
$sql="INSERT INTO Printing (name, page, date)
VALUES
('$_POST[name]','$_POST[page]', 'date()' )";
post the code that you are using to execute the $sql sentence ....
Here it is:
Code: Select all
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
EDIT| It's working now. Foolish of me to forget precious ' '.

Re: A Question
Posted: Fri Mar 19, 2010 3:52 am
by Luke
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
Posted: Fri Mar 19, 2010 4:06 am
by Tralalah
Duly noted, Luke. Thanks for that.
