Jump to content

What am i missing? php, mysql and timestamp autoupdate


justarandomguy

Recommended Posts

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.