Show error messages to a user when database insert fails

You should not use the $errors globally, but use hooks in WordPress development. Since you are new to WP development, I will explain briefly how it works.

What you should do instead:

  1. make a new hook, or use an existing one which you call at the
    location you want this error to appear in your template file.
  2. add the mytheme_insert_new_team function to this hook with
    add_action function

The syntax for this can be found here: https://code.tutsplus.com/tutorials/adding-custom-hooks-in-wordpress-custom-actions–cms-26454

A good explanation for how this exactly works is also found on that page under the section: Understanding WordPress Actions and then the subsection: Defining Custom Actions.

Here is the corresponding code I borrowed from that particular webpage:

<?php

/**
 * Define the action and give functionality to the action.
 */
 function tutsplus_action() {
   do_action( 'tutsplus_action' );
 }

 /**
  * Register the action with WordPress.
  */
add_action( 'tutsplus_action', 'tutsplus_action_example' );
function tutsplus_action_example() {
  echo 'This is a custom action hook.';
}

Now you have defined the action (hook) and registered the functionality to this hook with the 2nd part of the code.

Next, you want to make a call to this hook at the right location as following:

tutsplus_action()