eminempk Posted April 4, 2011 Share Posted April 4, 2011 Hey, i m a newbie in php,when i run the wamp server i got this error whn i click on my project. but when i click on Home, Gallery etc, then the error is gone i dont know what seems the problem is, help would be appreciated. here is the code of index.php <?php include("includes/header.html"); include("includes/navbar1.html"); if($_GET["page"] == "design"){ include ("includes/design.html"); } else if ($_GET["page"] == "gallery"){ include ("includes/gallery.html"); } else if ($_GET["page"] == "contact"){ include ("contact2.html"); } else if ($_GET["page"] == "about"){ include ("includes/About.html"); } else { include("includes/home.html"); } include("includes/footer.html"); ?> It loads the dynamic content, but first when i load it i got these errors as mentioned in the screenshot. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/232641-error/ Share on other sites More sharing options...
spiderwell Posted April 4, 2011 Share Posted April 4, 2011 page is undefined as its not a variable passed in the $_GET when you call the page first off. wrap the whole if statement in an other if statement that has isset($_GET['page']) personally I would do it this way: $page; if (isset($_GET['page']) $page = $_GET['page']; switch ($page) { case "design": include ("includes/design.html"); break; case "gallery": include ("includes/gallery.html"); break; case "contact": include ("includes/contact.html"); break; default: include ("includes/home.html"); } Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196566 Share on other sites More sharing options...
hyster Posted April 4, 2011 Share Posted April 4, 2011 u have else if ($_GET["page"] == "gallery"){ should be elseif ($_GET["page"] == "gallery"){ no space in elseif Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196568 Share on other sites More sharing options...
eminempk Posted April 4, 2011 Author Share Posted April 4, 2011 page is undefined as its not a variable passed in the $_GET when you call the page first off. wrap the whole if statement in an other if statement that has isset($_GET['page']) personally I would do it this way: $page; if (isset($_GET['page']) $page = $_GET['page']; switch ($page) { case "design": include ("includes/design.html"); break; case "gallery": include ("includes/gallery.html"); break; case "contact": include ("includes/contact.html"); break; default: include ("includes/home.html"); } I did wht u asked like this but now i get this error; ( ! ) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp server\www\Myweb\index.php on line 7 and line 7 is if (isset($_GET['page']) $page = $_GET['page']; <?php include("includes/header.html"); include("includes/navbar1.html"); $page; if (isset($_GET['page']) $page = $_GET['page']; switch ($page) { case "design": include ("includes/design.html"); break; case "gallery": include ("includes/gallery.html"); break; case "contact": include ("includes/contact.html"); break; default: include ("includes/home.html"); include("includes/footer.html"); } ?> Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196573 Share on other sites More sharing options...
spiderwell Posted April 4, 2011 Share Posted April 4, 2011 yeah sorry a small typo if (isset($_GET['page'])) $page = $_GET['page'] i only closed off one of the ) Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196577 Share on other sites More sharing options...
spiderwell Posted April 4, 2011 Share Posted April 4, 2011 also move the include footer out of the switch statement, or it will only appear in the homepage, not every page Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196578 Share on other sites More sharing options...
eminempk Posted April 4, 2011 Author Share Posted April 4, 2011 yeah sorry a small typo if (isset($_GET['page'])) $page = $_GET['page'] i only closed off one of the ) lol now i m getting an error in line 9 switch($page) { ( ! ) Parse error: syntax error, unexpected T_SWITCH in C:\wamp server\www\Myweb\index.php on line 9 can u post me the full code Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196579 Share on other sites More sharing options...
spiderwell Posted April 4, 2011 Share Posted April 4, 2011 hehe sure, sometimes I just overlook the simplest of errors, we are all human $page=''; if (isset($_GET['page'])) $page = $_GET['page']; switch ($page) { case "design": include ("includes/design.html"); break; case "gallery": include ("includes/gallery.html"); break; case "contact": include ("includes/contact.html"); break; default: include ("includes/home.html"); } include("includes/footer.html"); Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196582 Share on other sites More sharing options...
eminempk Posted April 4, 2011 Author Share Posted April 4, 2011 U Rock SpiderWell it worked thnx a lot... Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196584 Share on other sites More sharing options...
spiderwell Posted April 4, 2011 Share Posted April 4, 2011 got there in the end, thats the main thing, happy to help. Link to comment https://forums.phpfreaks.com/topic/232641-error/#findComment-1196585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.