Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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(); ?> 
share|improve this question

closed as off-topic by s_ha_dum Apr 2 at 15:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 2 down vote accepted

You are missing an <?php endif; ?>

[...]

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

endif;

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

[...]
share|improve this answer

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(); ?> 
share|improve this answer
    
thank-you for helping –  mattnewbie Apr 2 at 15:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.