Page 1 of 1

mysql date field

Posted: Wed Jun 11, 2003 12:35 am
by cbcampbell
i am trying to get a date, or timestamp field in mysql to automatically insert the current date of the time i create the record. However, everytime I create a new record, it sets the date and/or timestamp field to 0's all the way across. How do I fix this problem, or is it fixable?

Posted: Wed Jun 11, 2003 3:01 am
by []InTeR[]
How are you inserting this time?
Show us the query... :)

INSERT INTO `table` (`field`,`date`) VALUES ('foo',NOW())

Posted: Wed Jun 11, 2003 11:42 am
by cbcampbell
Actually, I am using this with php. I have a html form to fill out, then the values are entered into the database. I have a hidden field for the date inside the form because I just want the date field to be automatically entered when I click the submit button. However, that is my trouble. When the submit button is clicked, I execute my php script that enters the information into the database...below is the query I use....

INSERT INTO callog VALUES (' ','$call_date','$call_first','$call_last','$call_phone','$call_mess')";

the first field is blank because I have an ID field that automatically increments itself. The next field is the name of the date field. I've tried everything I can think of, but obviously not the right thing because I know there is a way to do this. I don't know if it is a php script thing, or a setting in my database that I need to change.

Posted: Wed Jun 11, 2003 11:48 am
by twigletmac
Could you not change the SQL to:

Code: Select all

INSERT INTO callog VALUES (' ', NOW(), '$call_first', '$call_last', '$call_phone', '$call_mess')
as []InTeR[] suggested - NOW() will give you the date (and time if applicable) that the record was inserted.

Mac

Posted: Wed Jun 11, 2003 2:38 pm
by cbcampbell
thank you very much. yes, that fixed it. I am sort of a n00b with SQL.