0

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"; }; } ?> ``` 
1
  • 1
    Seems like endless recursion... Commented Dec 18, 2020 at 6:02

3 Answers 3

1

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"; }; 
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming that all the pages are in the same directory. Try this

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

1 Comment

Thanks! I used both of you guys answer and it worked!
0

Here's the example on how to check if the file exists and then include it in the navigation... simply use index.php?nav=Something

<?php if ($_GET['nav']) { $nav = strtolower($_GET['nav']); } else { $nav = "main"; } $folder = "./nav/"; $extens = ".php"; $mainfl = $folder."main".$extens; switch($nav) { case "about": $filenm = $folder.strtolower($nav).$extens; if (file_exists($filenm)) { include($filenm); } else { include($mainfl); } break; case "download": $filenm = $folder.strtolower($nav).$extens; if (file_exists($filenm)) { include($filenm); } else { include($mainfl); } break; case "products": $filenm = $folder.strtolower($nav).$extens; if (file_exists($filenm)) { include($filenm); } else { include($mainfl); } break; default: include($mainfl); } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.