How to let a user create a post by submitting a POST form?

The echo part should be at the end of your code.
Keep that in mind, any echo or print should be at the end of your piece of code.

<?php
    if( $_POST['title_given'] ) {
        // Create post object
        $my_post = array(
          'post_title'    => wp_strip_all_tags( $_POST['title_given'] ),
          'post_content'  => 'Did it work??',
          'post_status'   => 'publish',
          'post_author'   => 1,
          'post_type'     => 'post'
        );
    
        // Insert the post into the database
        $return_value = wp_insert_post( $my_post, true );   
        
        // This echo never appears for some reason
        echo "Title given is: " . $_POST['title_given'] . "<br />";
        echo "wp_insert_post() returned: " . var_dump( $return_value ) . "<br />";
   
    }