-3

Doing some very basic coding on codeacademy and this has been bugging me for over an hour now. What is possibly wrong with this code that it is displaying the error " Parse error: syntax error, unexpected T_ELSEIF on line 12 "

<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items = 10;    // Set this to a number greater than 5!
        if ($items > 5) {
          echo "You get a 10% discount!"; }
          else { echo "You get a 5% discount!";
          } elseif ($items == 1) {
              echo "Sorry, no discount!";
          }


      ?>
    </p>
  </body>
</html>
roukzz
  • 129
  • 1
  • 2
  • 10
  • You can not use `elseif` after `else`.[http://php.net/manual/en/control-structures.elseif.php](http://php.net/manual/en/control-structures.elseif.php) – Naveed May 17 '13 at 23:07
  • [Reference - What does this error mean in PHP?](http://stackoverflow.com/q/12769982) <- Error in PHP you have no clue about? This should be one of your first stops online. – hakre May 18 '13 at 22:00

2 Answers2

8

The else block must be last. It cannot go before an else if:

if ($items > 5) {
    echo "You get a 10% discount!";
} else if ($items == 1) {
    echo "Sorry, no discount!";
} else {
    echo "You get a 5% discount!";
}
Blender
  • 289,723
  • 53
  • 439
  • 496
4

Your else block needs to be the last if you intend to use else if. Please watch your use of { and } as well. If it's messy, it's hard to read and harder to debug.

<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items = 10;    // Set this to a number greater than 5!
        if ($items > 5) {
            echo "You get a 10% discount!";
        } else if ($items == 1) {
            echo "Sorry, no discount!"; 
        } else { 
            echo "You get a 5% discount!";
        }
      ?>
    </p>
  </body>
</html>
Kevin
  • 523
  • 4
  • 20
  • now it tells me "Oops, try again! Did you remember to include the elseif keyword?" using the exact code you gave me. **EDIT** needed to be elseif not else if. I'm pretty sure they were the same. – roukzz May 17 '13 at 23:16
  • 1
    Must be some codeacadamy requirement. All I can confirm for you is that this code is valid PHP. – Kevin May 17 '13 at 23:22