correct validate and sql query

What you’re doing is safe.

However, some notes:

  1. See the WP_User_Query class in the Codex. This is the, “official,” way to do something like this, although you’ll get an integer-indexed array of WP_User objects. Instead of the ARRAY_A that you’ve specified.
  2. You probably don’t want _my_table, unless your table is called something like wp__my_table (note the double underscore after wp). The prefix returned from $wpdb->prefix includes the underscore that many installations use after the prefix.
  3. The trim() call after sanitize_user() is superfluous. It doesn’t hurt anything but it’s also a waste of compute cycles.
  4. You may be able to write this in one line: $results = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}my_table where name = %s", sanitize_user($_POST['name'])), ARRAY_A); This may be better or worse for you.