-3

Error I'm getting is:

Parse error: syntax error, unexpected '{' in xxx on line 272

Line 272 is:

<?php 

     if(htmlentities($shop['categorie']) == '1') 
     { echo "Achtergronden"; }
     elseif(htmlentities($shop['categorie']) == '2') 
     { echo "Widgets"; } 
     elseif(htmlentities($shop['categorie']) == '3') 
     { echo "Overig"; } 

?>
Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
Carl
  • 23
  • 6
  • 4
    `else` doesn't take arguments, you need to make it a `else if` , Although from what I can see you might wanna use a [switch();](http://php.net/manual/en/control-structures.switch.php) instead. – Epodax Mar 03 '16 at 14:08
  • @Epodax Hmm, strange. Never heard of this `else` issue. Thanks! – Carl Mar 03 '16 at 14:13
  • `Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE.` -http://php.net/manual/en/control-structures.else.php – chris85 Mar 03 '16 at 14:15
  • It's always been that way, `else` is meant as a "fall back" / default if the `if` condition isn't met. It's not suppose to take arguments – Epodax Mar 03 '16 at 14:15
  • https://3v4l.org/ is a great tool to check code blocks for syntax issues and execution compatibility. Also recommend using a code style guide. – David J Eddy Mar 03 '16 at 14:25

2 Answers2

2

Problem in else with condition

<?php 
if(htmlentities($shop['categorie']) == '1') {
  echo "Achtergronden"; 
} elseif(htmlentities($shop['categorie']) == '2') {
  echo "Widgets"; }
// your version: else(htmlentities($shop['categorie']) == '3') {
// and correct one below
elseif(htmlentities($shop['categorie']) == '3') {
    echo "Overig"; 
} ?>
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
  • Since when does `else` cause these issues? Thanks for the answer. – Carl Mar 03 '16 at 14:13
  • It's can be rewrite to use switch case, or even so $ar = array('1' => 'Achtergronden', '2' => 'Widgets', '3' => 'Overig'); echo !empty($ar[htmlentities($shop['categorie'])]) ? $ar[htmlentities($shop['categorie'])] : ''; – alexander.polomodov Mar 03 '16 at 14:17
0

You must use else ifrather than else in last condition

<?php 

  if(htmlentities($shop['categorie']) == '1') 
  { echo "Achtergronden"; }
  elseif(htmlentities($shop['categorie']) == '2') 
  { echo "Widgets"; } 
  elseif(htmlentities($shop['categorie']) == '3') 
  { echo "Overig"; } 

?>
Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75