-3

why cant i run this part of my code is showing some syntax error on the last line

Parse error: syntax error, unexpected token "}", expecting "," or ";"

<?php
    if (alert) {
        echo ' <div class="alert alert-primary" role="alert">
        A simple primary alert—check it out!
      </div> '
    }
    
   ?>
brombeer
  • 8,716
  • 5
  • 21
  • 27
itsnitinn
  • 1
  • 1
  • 1
    Missing `;` after echo+string – Honk der Hase Sep 18 '21 at 08:35
  • `unexpected token XYZ` means something _before_ that token has gone wrong. `expecting "," or ";"` means PHP ... expected a `,` or `;` – brombeer Sep 18 '21 at 08:40
  • `if (alert)` is fine? Nothing to complain there? – brombeer Sep 18 '21 at 08:41
  • 3
    Being a newbie doesn't mean you can't do some research. Searching for "Parse error: syntax error, unexpected token" on this site could have lead you to [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them). Please don't take this the wrong way, it's just that some questions have already been answered in detail. Happy coding – brombeer Sep 18 '21 at 08:48

1 Answers1

1

What you forgot in your code is the ; and the end of the echo.

Your code should look like the following

 if (alert) {
    echo ' <div class="alert alert-primary" role="alert">
    A simple primary alert—check it out!
  </div> '; // added the ; at the end
}

Remember that in php, each command should end with the ; character

ThomasSquall
  • 644
  • 6
  • 21