0

I have a problem with setting an active class to the menu. Here is my code:

<ul class="main-nav nav navbar-nav">
    <li class="<?= (basename($_SERVER['PHP_SELF'] == 'index.php') ? 'active' : ''; ?> "><a href="index.php">Эхлэл</a></li>
    <li class="<?= (basename($_SERVER['PHP_SELF'] == 'product.php') ? 'active' : ''; ?> "><a href="product.php">Бүтээгдэхүүн</a></li>
    <li class="<?= (basename($_SERVER['PHP_SELF'] == 'about.php') ? 'active' : ''; ?> "><a href="about.php">Бидний тухай</a></li>
    <li class="<?= (basename($_SERVER['PHP_SELF'] == 'contact.php') ? 'active' : ''; ?> "><a href="contact.php">Холбоо барих</a></li>
</ul>

And result is:

Parse error: syntax error, unexpected ';' in E:\xampp\htdocs\tgnm\header.php on line 131

What am i doing wrong ? and this code will be work ?

Dhruv
  • 612
  • 7
  • 15
batgerel.e
  • 837
  • 1
  • 10
  • 31

1 Answers1

0

Sorry, You have to complete bracket add to before "==" this location. Please update the below code.

                <ul class="main-nav nav navbar-nav">
                    <li class="<?= (basename($_SERVER['PHP_SELF']) == 'index.php') ? 'active' : ''; ?> "><a href="index.php">Эхлэл</a></li>
                    <li class="<?= (basename($_SERVER['PHP_SELF']) == 'product.php') ? 'active' : ''; ?> "><a href="product.php">Бүтээгдэхүүн</a></li>
                    <li class="<?= (basename($_SERVER['PHP_SELF']) == 'about.php') ? 'active' : ''; ?> "><a href="about.php">Бидний тухай</a></li>
                    <li class="<?= (basename($_SERVER['PHP_SELF']) == 'contact.php') ? 'active' : ''; ?> "><a href="contact.php">Холбоо барих</a></li>
                </ul>
Bhavin Thummar
  • 1,255
  • 1
  • 12
  • 29
  • For your information, if you want to check php syntax error. You can use this online tool. https://phpcodechecker.com/ – Bhavin Thummar Nov 29 '19 at 10:09
  • Please don't answer questions where the solution is "Fix the typo". This type of question has no long term value since other people with the same problem are not going to find this by searching. "Typo" is one of the standard Close Vote reasons. Answering this type of question can block the OP from deleting it to remove bloat from StackOverflow. – John Conde Nov 29 '19 at 13:46