-1

Why's the endif; not working? Can't figure it out. I apologize beforehand because It's probably a stupid typo or something but as I said I can't figure it out.

Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /Applications/XAMPP/xamppfiles/htdocs/jqueryphp/views/index.tmpl.php on line 28

<?php include "_partials/header.php"; ?>

<h1>Search actors by last name</h1>

<form action="index.php" method="post">
    <select name="q" id="q">
        <?php
        $alphabet = str_split("abcdefghijklmnopqrstuvxyz");

        foreach ( $alphabet as $letter ) {
            echo "<option value='$letter'>$letter</option>";
        }
         ?>
    </select>
    <button type="submit" name="button">
        Go!
    </button>
</form>

<?php if ( isset($actors) ) ?>

<ul class="actors_list">
    <?php foreach( $actors as $a ) {
        echo "<li>{$a->first_name} {$a->last_name}</li>";
    }
    ?>
</ul>
<?php endif; ?>

<?php include "_partials/footer.php"; ?>
Panda
  • 6,955
  • 6
  • 40
  • 55

2 Answers2

1

Try This Please you did not put ":" to end of IF

<?php if ( isset($actors) ){ ?>

<ul class="actors_list">
    <?php foreach( $actors as $a ) {
        echo "<li>{$a->first_name} {$a->last_name}</li>";
    }
    ?>
</ul>
<?php } ?>

or

<?php if ( isset($actors) ): ?>

<ul class="actors_list">
    <?php foreach( $actors as $a ) :
        echo "<li>{$a->first_name} {$a->last_name}</li>";
    endforeach;
    ?>
</ul>
<?php endif; ?>
Ivan Barayev
  • 2,035
  • 5
  • 24
  • 30
1

if you want to use the endif; syntax, instead of a { you must use a : in the if

The syntax is

if () :
else :
endif;

You can also use

foreach():
endforeach;

So corrected code is

<?php if ( isset($actors) ) : ?>

<ul class="actors_list">
    <?php foreach( $actors as $a ) :
        echo "<li>{$a->first_name} {$a->last_name}</li>";
    endforeach;
    ?>
</ul>
<?php endif; ?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149