Replaced query with wpdb->insert

Finished converting from wpdb->query to the better wpdb->insert and wpdb->update functions.