How to Check User type from the form user registers in user_register hook?

This is just an alternative answer and not the expected answer to the question. I was searching for ways to find which user is teacher or student from the registration form they register. From what I understand, it can be done through checking the form metakey relationship in the user_meta table. This is a way to find which data is stored for teacher and which for student. Using this we find out the teacher and student.
In my question I was using a function in user_register hook to get the userid of the user immediately after the user registers. But this has a problem.

Not all meta data is accessible using the user_meta table in this function. This I got from this question of stackoverflow
How to get user_meta value for new user regsitered?

The alternative solution that I suggest is to add the discount for user on first login. This is done to get access to the user_meta data completely and also find which user is teacher and which user is student. Here is the code for this:

add_action( 'user_register', 'function_new_user');

function function_new_user($user_id) { 
   add_user_meta( $user_id, '_new_user', '1' );
}

add_action('wp_login', 'function_check_login_redirect', 10, 2);


function function_check_login_redirect($user_login, $user) {
   $logincontrol = get_user_meta($user->ID, '_new_user', 'TRUE');
if ( $logincontrol ) 
{
    $user_id = $user->ID;
    update_user_meta( $user->ID, '_new_user', '0' );
    global $wpdb;
    $count_query ="SELECT * FROM discount_for_users WHERE userid='$user_id'";
    $results = $wpdb->get_results ( "SELECT * FROM discount_for_users WHERE userid='$user_id'" );
    $numrows = $wpdb->get_var($count_query);
    
    if( $user->has_cap( 'administrator') or $user->has_cap( 'author')) 
    {
        $discountMonths = 0;
        $discountValue = 0;
        $disctype="admin";
    } 
    elseif( metadata_exists( 'user', $user_id, 'studentmothermobile' )) 
    {
        $disctype="student";
            $stdDiscount = $wpdb->get_results ( "SELECT * FROM student_discount WHERE status="active" LIMIT 1" );
            foreach ( $stdDiscount as $print ) 
            {
                $val=1;
                $discountMonths =$print->months;
                $discountValue =$print->discount;
            }
    }
    elseif ( metadata_exists( 'user', $user_id, 'teachdobmeta' ) ) 
    {
        $disctype="teacher";
            $tearesult = $wpdb->get_results ( "SELECT * FROM teacher_discount WHERE status="active" LIMIT 1" );
            foreach ( $tearesult as $teachprint ) 
            {
                $val=1;
                $discountMonths =$teachprint->months;
                $discountValue =$teachprint->discount;
            }
    }
    else 
    {
        $discountMonths = 0;
        $discountValue = 0;
        $disctype="user";
        
    }
        
          $table="discount_for_users";
          $data = array(
              'userid' => $user_id,
              'discount' => $discountValue,
              'vaildity' => $discountMonths,
              'type' => $disctype,
          );
          $format = array(
              '%d',
              '%d',
              '%d',
              '%s',
          );
          $success=$wpdb->insert( $table, $data, $format ); 
      
       
   }
}

In the solution we add value 1 to the user meta data on registering and update it to 0 on first login. There is condition which checks whether the meta data value is 1 and run the function. So it runs the function first time only and we are able to add discount associated with teacher and student based on the type using this method.
Please note this is alternate solution and if there is a direct solution which can solve this problem, please provide it. It will be helpful. Our first priority is to add discount on registration and not on first login.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)