Check if row exists before inserting

There are several problems with your function. For example, $tablename points to a table that does not exist. And you don’t need it anyway.
If you are trying to create a new user if that email does not exist then try this:

function register_user() {
    global $wpdb; 
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];  

    $checkIfExists = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE email="$email"");

    if ($checkIfExists == NULL) {

        $userdata = array(
            'user_login'    =>  $name,
            'user_email'    =>  $email,
            'user_pass'     =>  $password,
        );

        $user = wp_insert_user( $userdata );
        
    }
    
}