database: function to save events