Fixed insert to database function.