validation and insert to db