Fixing wrong use of database::query and database::insert_id() (changes in old code)