Match tag names with form titles

I am trying to match tag names with form titles to fetch the correct form into the current post, to subscribe to new posts tagged with the current posts tag. I only have 1 tag assigned per post.

The code for categories works well, and I tried to transcribe it for tags, but I am afraid there are syntax errors in the code, because it does not work.

How do I write the correct code?

add_shortcode( 'subscribe-to-tag', function() {    global $  wpdb, $  post;   $  the_tag = get_the_tags( $  post->ID ); $  tag_name = $  the_tag[0]->tag_name;    $  id = $  wpdb->get_var($  wpdb->prepare("SELECT ID FROM wptq_forms WHERE name = '{$  tag_name}';"));    if (is_null($  id)) { return ''; }    return do_shortcode( '[newsletter_form id="' . intval( $  id ) . '"]' ); } );