adwarm — 2012-11-16T10:51:41-05:00 — #1
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,'')",
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!
r937 — 2012-11-16T11:08:30-05:00 — #2
could you do a SHOW CREATE TABLE for that table please
adwarm — 2012-11-16T11:11:38-05:00 — #3
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.
kylewolfe — 2012-11-16T12:17:12-05:00 — #4
Do not include the timestamp in your INSERT statement. Your telling it to add a null time stamp rather than letting it do its thing.
adwarm — 2012-11-16T12:20:56-05:00 — #5
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)",
cpradio — 2012-11-16T12:26:50-05:00 — #6
SHOW CREATE TABLE logs
adwarm — 2012-11-16T12:35:14-05:00 — #7
Thanks, below is the information:
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 (
) ENGINE=MyISAM AUTO_INCREMENT=174 DEFAULT CHARSET=latin1
r937 — 2012-11-16T14:16:37-05:00 — #8
( EditedBy , Log )
( %s , %s )
do not mention the columns that have a default behaviour
two of yours do, two don't
supply values only for the columns that don't
rcashell — 2012-11-16T16:04:27-05:00 — #9
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.
$query6 = sprintf("INSERT INTO logs VALUES (null,%s,%s,null)",
Would have worked.
kylewolfe — 2012-11-16T16:07:09-05:00 — #10
You should not be passing the value at all, not even using NULL, as r937 and I stated.