justarandomguy Posted March 10, 2011 Share Posted March 10, 2011 Hello again; I'm trying to build a little php site and some with mysql, when a record is saved on the DB i want a column with the timestamp. I've been doing a bit of reading and *i think* the database part is done but i cant figure how the insert should be done. The column on mysql is: Type: timestamp Default: current_timestamp Attributes: on update current_timestamp The structure on the table is: id, timestamp, column1, column2. I thought that since it is 'on update current_timestamp' it would fill itself properly, but when i do my insert: $query = "INSERT INTO tbl_process VALUES ('','','$value1','$value2')"; mysql_query($query) or die ("Error in query: $query " . mysql_error()); The only saved value is "0000-00-00 00:00:00" so obviusly i'm missing something... for extra points: the 'id' value is autoincrement so on the insert i just leave the value empty with ''. Is that the "correct" way of filling that field or is there a "best practice" for that? Thanks everyone Link to comment https://forums.phpfreaks.com/topic/230272-what-am-i-missing-php-mysql-and-timestamp-autoupdate/ Share on other sites More sharing options...
AbraCadaver Posted March 10, 2011 Share Posted March 10, 2011 Try: $query = "INSERT INTO tbl_process VALUES (DEFAULT, DEFAULT, '$value1','$value2')"; //or $query = "INSERT INTO tbl_process (column1, column2) VALUES ('$value1','$value2')"; Link to comment https://forums.phpfreaks.com/topic/230272-what-am-i-missing-php-mysql-and-timestamp-autoupdate/#findComment-1185844 Share on other sites More sharing options...
justarandomguy Posted March 10, 2011 Author Share Posted March 10, 2011 Nice! that did the trick! Thanks! Link to comment https://forums.phpfreaks.com/topic/230272-what-am-i-missing-php-mysql-and-timestamp-autoupdate/#findComment-1185864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.