I need some help please, for some reason when a new record is added the field called TimeStamp is left blank. Here is how the field is setup:
Column Type Attributes Null Default Extra
TimeStamp timestamp on update CURRENT_TIMESTAMP No CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Can anyone see anything as to why on a new record its left as 0000-00-00 00:00:00 ?
Below is the PHP code i am using to insert a new record:
$query6 = sprintf("INSERT INTO logs VALUES ('',%s,%s,'')",
quote_smart($FullName),
quote_smart($log6));
The last part thats blank ‘’ is for the TimeStamp as iv left it blank thinking when a new record is added MySQL will add the current time/date automatically, any help would be great!
Thanks for the reply, I’ve never used that function before so not sure what im suppose to do with it, when i enter it in the SQL for PHPMYADMIN its coming up with an error. Can you give me some guidance please.
I’ve change it to this but its still not adding the time stamp:
$log = "added a new contact - $postfullname from $CompanyName";
$query4 = sprintf("INSERT INTO logs VALUES ('',%s,%s)",
quote_smart($FullName),
quote_smart($log));
CREATE TABLE logs ( LogID int(11) NOT NULL AUTO_INCREMENT, EditedBy text NOT NULL, Log text NOT NULL, TimeStamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (LogID)
) ENGINE=MyISAM AUTO_INCREMENT=174 DEFAULT CHARSET=latin1
The issue here is that you are looking for the default behavior for timestamp but you are attempting to register an empty string as a timestamp value. This is not permitted. As r937 described above you should really name the columns you do not want default behavior for. Another way of doing this is passing a NULL value when you want the default behavior to be initiated.
For example:
$query6 = sprintf("INSERT INTO logs VALUES (null,%s,%s,null)",
quote_smart($FullName),
quote_smart($log6));