What is the best way to do this? [closed]

Let’s start with proper indenting your code:

<select name="select-city" onchange="location = this.value;">
    <option value="">Select a post to read</option>
    <?php
        if ( is_user_logged_in() ):
            global $current_user;
            wp_get_current_user();
            $author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
            $author_posts = new WP_Query($author_query);
            $numposts = count_user_posts( $user_id ); // <- you can't use $count_user_posts also - it's a function, not a variable
            while ( $author_posts->have_posts() ) :
                $author_posts->the_post();
    ?>
                <option value="<?php the_permalink(); ?>"><?php the_title(); ?></option>
            <?php
                elseif ($numposts == 0) :  // <- here's the problem - there is an elseif, but there was no if earlier
                    echo 'You have no posts';
            ?>
                    <?php endwhile;  // <- and here is another problem, because you use endwhile in elseif, but there was no while in that elseif...
                else :
                    echo '<a href="https://www.mysiteeeee.com/wp-login.php" >Log in</a>';
                endif; ?>

As you can see there clearly is something wrong with that code, because you can’t indent it.

So how should that look? It’s hard to be certain, but… I’m pretty sure it should be something like this:

<?php if ( is_user_logged_in() ): ?>
    <?php
        global $current_user;
        wp_get_current_user();
        $author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
        $author_posts = new WP_Query($author_query);
        $numposts = count_user_posts( $user_id );
        if ( $numposts ) :  // if there are posts, then show <select>
    ?>
        <select name="select-city" onchange="location = this.value;">
            <option value="">Select a post to read</option>
            <?php while ( $author_posts->have_posts() ) : $author_posts->the_post(); ?>
                <option value="<?php the_permalink(); ?>"><?php the_title(); ?></option>
            <?php endwhile; ?>
        </select>
     <?php else : // if there are no posts ?>
         You have no posts
     <?php endif; ?>
<?php else : // you can't show links inside of select, so this is elseif for ( is_user_logged_in() ?>
    <a href="https://www.mysiteeeee.com/wp-login.php" >Log in</a>
<?php endif; ?>