Parse error: syntax error, Unexpected ';' in C: xampp htdocs edit-anuncio.php on line 68

Asked

Viewed 982 times

0

My line 68 is like this.

<option value="0"<?php echo ($info['estado']=='0')?'selected="selected"';'';?>>Não Pago</option>
  • Your question is very broad. But I will leave an answer.

  • You put a ; in the ternary operator, but the ternary :. Instead of writing ?:, you wrote ?;

2 answers

1

As I can not test at this time by is on mobile, I will leave two options below:

Option 1:

<option value="0" <?php echo ($info['estado']=='0')?' selected ="selected"' : ''; ?>>Não Pago</option>

Option 2:

<?php
if($info['estado']=='0') $select = ' selected="selected"'; else $select = "";
?>
<option value="0"<?php echo $select; ?>>Não Pago</option>

Good luck!

  • 1

    In option 2, there was no gap between the value="0" and the content of the variable $select? In my reading, in case the comparison is true, it will come out value="0"selected="selected"

  • That’s no problem, but I edited it and put the space.

  • If my answer helped you, please mark as resolved.

0

I think that’s what you want:

<?php if ($info['estado']=='0') {?> 
    <option value="0" selected="selected">Não Pago</option>
<?php } else { ?>
    <option value="0">Não Pago</option>
<?php } ?>
  • I believe that this solution that you have now presented is very verbose. I prefer a greater concision, less repetition... And also PHP offers a more user-friendly syntax for making these blocks in the middle of HTML, if (cond):, else:, endif

  • Thank you very much.

Browser other questions tagged

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