mysql date field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cbcampbell
Forum Newbie
Posts: 19
Joined: Mon Jun 09, 2003 12:12 am

mysql date field

Post 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?
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

How are you inserting this time?
Show us the query... :)

INSERT INTO `table` (`field`,`date`) VALUES ('foo',NOW())
User avatar
cbcampbell
Forum Newbie
Posts: 19
Joined: Mon Jun 09, 2003 12:12 am

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
cbcampbell
Forum Newbie
Posts: 19
Joined: Mon Jun 09, 2003 12:12 am

Post by cbcampbell »

thank you very much. yes, that fixed it. I am sort of a n00b with SQL.
Post Reply