Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in this template?

I’m trying to echo a form, when the user is logged in, I get this in the browser when I upload the code:

syntax error, unexpected 'endwhile' (T_ENDWHILE) in

Read More

My code:

<?php
/*
Template Name: Customers
*/

get_header(); ?>

    <div id="primary" class="site-content">
        <div id="content" role="main">

            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page' ); ?>
                <?php if (is_user_logged_in()):

echo '<form type="post" action="" id="newCustomerForm"> ';

echo '<label for="name">Name:</label>';
echo'<input name="name" type="text" />';

echo'<label for="email">Email:</label>';
echo'<input name="email" type="text" />';

echo'<label for="phone">Phone:</label>';
echo'<input name="phone" type="text" />';

echo'<label for="address">Address:</label>';
echo'<input name="address" type="text" />';

echo'<input type="hidden" name="action" value="addCustomer"/>';
echo'<input type="submit">';
echo'</form>';
echo'<br/><br/>';
echo'<div id="feedback"></div>';
echo '<br/><br/>';

else:
echo 'Sorry, only registered users can view this information';
?>

            <?php endwhile; // end of the loop. ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?> 

Related posts

Leave a Reply

2 comments

  1. You are missing an <?php endif; ?>

    [...]
    
    else:
    echo 'Sorry, only registered users can view this information';
    
    endif;
    
    <?php endwhile; // end of the loop. ?>
    
    [...]
    
  2. You forgot to end the if statement. this should work:

       <div id="primary" class="site-content">
            <div id="content" role="main">
    
                <?php while ( have_posts() ) : the_post(); ?>
                    <?php get_template_part( 'content', 'page' ); ?>
                    <?php if (is_user_logged_in()):
    
    echo '<form type="post" action="" id="newCustomerForm"> ';
    
    echo '<label for="name">Name:</label>';
    echo'<input name="name" type="text" />';
    
    echo'<label for="email">Email:</label>';
    echo'<input name="email" type="text" />';
    
    echo'<label for="phone">Phone:</label>';
    echo'<input name="phone" type="text" />';
    
    echo'<label for="address">Address:</label>';
    echo'<input name="address" type="text" />';
    
    echo'<input type="hidden" name="action" value="addCustomer"/>';
    echo'<input type="submit">';
    echo'</form>';
    echo'<br/><br/>';
    echo'<div id="feedback"></div>';
    echo '<br/><br/>';
    
    else:
    echo 'Sorry, only registered users can view this information';
    ?>
    
                <?php  endif;?>
                <?php endwhile; // end of the loop. ?>
    
    
            </div><!-- #content -->
        </div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>