Skip to content
Advertisement

switch pages navigation bar php

I’m trying to link my pages so I can switch from when to another through navigation bar but it’s not working and keeps reloading none stop without a result.

in my html nav bar :

<div id="topnav">
<a href="?page=index.php">Home</a>
<a href="?page=About.php">About</a>
<a href="?page=Contact.php">Contact</a>
</div>

in my index.php

  if (!isset($_GET['page'])) {
    include "index.php";
  } else {
    switch ($_GET['page']) {
      case "About":
        include "About.php";
        break;
      case "contact":
        include "Contact.php";
        break;
      default:
        include "index.php";
    };
  }
  ?> ```

Advertisement

Answer

The Switch cases don’t seem to match with the page parameters…

// amending the case values
switch ($_GET['page']) {
  case "About.php":
    include "About.php";
    break;
  case "Contact.php":
    include "Contact.php";
    break;
  default:
    include "index.php";
};
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement