Else does not work in PHP

Asked

Viewed 341 times

2

I’m trying to use the code below, but the else does not work. Returns error Parse error: syntax error, unexpected 'else' (T_ELSE)

<?php if ($status == 'True') ?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
    <img src="'.$poster.'" class="poster">
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
    <div class="imdb-panel">
        <div class="imdb-head">
            <?php echo $title; ?>
        </div>
        <div class="imdb-body">
            <p style="margin: 0">Nome: <?php echo $title ?></p>
            <br>
            <p style="margin: 0">Data de lançamento: <?php echo $released ?></p>
            <br>
            <p style="margin: 0">Dirigido por: <?php echo $director ?></p>
            <br>
            <p style="margin: 0">Escrito por: <? echo $writer ?></p>
            <br>
            <p style="margin: 0">Elenco principal: <?php echo $actors ?></p>
        </div>
    </div>
</div>
<?php else: ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <div class="imdb-panel">
        <div class="imdb-head">
            Título não encontrado
        </div>
        <div class="imdb-body">
            <p style="text-align: center;">O título que você procurou não pode ser encontrado.</p>
        </div>
    </div>
</div>
<?php endif ?>

1 answer

4


Missed the : in the first line:

<?php if ($status == 'True'): ?>
----------------------------^

And ; in the end:

<?php endif; ?>
-----------^

In the third line, there’s something that doesn’t make sense:

<img src="'.$poster.'" class="poster">
-----------^^^^^^^^^

Would you be concatenating a PHP variable within HTML? Replace with echo:

<img src="<?php echo $poster; ?>" class="poster">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.