query_vars doesn’t return query string (trying to get data from $wpdb)

I think the issue may be that you think query_vars can pick up the query string arguments from a URL, but you don’t need to do it that way. That’s primarily used if you’re needing to get this into the WP Query (which isn’t what you’re doing here). It’s much easier to simply check for the query param with $_GET.

Here’s how you need to approach it:

<?php

/*
* Step 1:
* Get reference query param from URL
*/

// Check with isset() so you don't get undefined errors.
// Use a null value as a default so your query will still run.
$reference = ( isset( $_GET['ref'] ) ) ? sanitize_text_field( $_GET['ref'] ) : '';

/*
* Step 2:
* Get data from row in wp_invites table where reference equals what's in the query string
*/

global $wpdb;

$table_name = $wpdb->prefix . 'invites';

$results = $wpdb->get_results(
  $wpdb->prepare( "SELECT * FROM $table_name WHERE reference=%s", $reference), ARRAY_A
);


var_dump($results);
  
if( $results ){
  foreach ($results as $result){
    echo '<p>'. $result['lead_name'] . '</p>';
  }
}

?>