spacka Posted January 25, 2008 Share Posted January 25, 2008 ok basically im making a website and i know what the srtucture is going to be like and i know that i want something like the following: index.php?course=sport&level=2 this page would be located in "/pages/level1/sport.htm" or something similar. i know i havent got this far yet with the following code, but even what i have got is bringing up an error: <?php $page = $_GET['page']; if (!file_exists("$page.htm") && isset($page)) { include($page . ".htm"); } else { include ("main.htm"); } ?> as you can see - http://69.41.171.40/arctic/vocationalacademy/ - its not quite working. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/ Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 what is on line 23 of index.php ? Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448734 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 $page = $_GET['page']; Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448735 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 i mean, i know that at the minute theres not enough code to go as far as "index.php?course=sport&level=2" but what i should be able to do with the code ive got for right now is something like "index.php?page=level2" to bring up whats in "/pages/level2.htm" Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448736 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 looking at your URL you should use "course" $page = $_GET['course']; Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448739 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 yeah no, sorry. thats just what i WANT to have when ive sorted everything. i'll be able to change words once im done, but at the minute im just stuck with the whole idea of getting it working. its been ages since ive used php, and i was never THAT great anyway. but at the minute i have: VOCATIONAL ACADEMY FOLDER--> --index.php --main.htm --PAGES FOLDER--> ----level1.htm ----level2.htm ----level3.htm ----entrylevel.htm "main.htm" contains something like 'IF YOU ARE READING THIS THEN ITS WORKING' and it loads fine, but theres also that line 23 error, and theres also the factt hat i cant include the filesi want to include from pages folder. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448743 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 post your script code... Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448745 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 here's my whole index.php file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <link rel="stylesheet" href="new.css"> </head> <body marginheight="0" marginwidth="0"> <table width="781" border="0" cellpadding="0" cellspacing="0" class="contentmain"> <tr> <td><p><img src="images/header.png" width="781" height="142"></p> <p> </p></td> </tr> <tr> <td><img src="images/sidebar.png" width="658" height="31"></td> </tr> <tr> <td><div align="left"> <?php $page = $_GET['page']; if (!file_exists("/pages/$page.htm") && isset($page)) { include($page . ".htm"); } else { include ("main.htm"); } ?> </div></td> </tr> <tr> <td><img src="images/footer.png" width="781" height="68"></td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448748 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 this if (!file_exists("/pages/$page.htm") && isset($page)) { include($page . ".htm"); } else { include ("main.htm"); } should of been if (file_exists("/pages/$page.htm") && isset($page)) { include($page . ".htm"); } else { include ("main.htm"); } notice the !file_exists is changed to file_exists it will take out the error.. its a logical error.. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448749 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 ive just changed that and nothing different happens http://69.41.171.40/arctic/vocationalacademy/index.php Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448754 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 its working fine try http://69.41.171.40/arctic/vocationalacademy/index.php?page=level1 if level1.htm is there in the pages/ directory it will show.. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448759 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 http://69.41.171.40/arctic/vocationalacademy/pages/level1.htm Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448760 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 http://69.41.171.40/arctic/vocationalacademy/index.php?page=level1 still doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448763 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 this if (file_exists("/pages/$page.htm") && isset($page)) { should be if (file_exists("pages/$page.htm") && isset($page)) { notice that I removed the first "/" Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448766 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 sorry made a mistake again your code should be if (file_exists("pages/$page.htm") && isset($page)) { include("pages/{$page}.htm"); } else { include ("main.htm"); } Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448768 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 aaah yes, thats it. you see, i knew it was something about the way i pointed to the directories, because when i had index.php in the same folder as level1.htm, it worked, but then i could figure out how to do the following line: include("pages/{$page}.htm"); i kept trying to add quotations and came up with things like include("pages/$page} . ".htm""); which obvously came up with errors. thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448772 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 Welcome... glad to be of help! Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448773 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 sorry to be a pain, but now that we know how to do this, what code would i add to get something like this: index.php?page=level1&course=sport obviously we know that level1.htm is in /pages/, but sport.htm is in /pages/level1/ any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448779 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 your code should be <? $page = $_GET['page']; $course = @$_GET['course']; if (isset($page) && isset($course) && file_exists("pages/{$page}/{$course}.htm")) { include("pages/{$page}/{$course}.htm"); } else if (isset($page) && file_exists("pages/{$page}.htm")) { include("pages/{$page}.htm"); } else { include ("main.htm"); } ?> this will take care of index.php?page=level1 - show level1.htm in pages/ folder index.php?page=level1&course=sport - show sport.html in pages/level1 folder hope its helpful Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448784 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 yeah that sounds good. also, i will have the same for level 2, level 3 and maybe others. so would it be easiest to just repeat the code to goto /pages/level2/sport.htm, /pages/level3/sport.htm etc, or is there an easier/better way? this sounds good so far, though, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448787 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 no the current code will take care of it just give links like ndex.php?page=level2 - show level2.htm in pages/ folder index.php?page=level2&course=sport - show sport.html in pages/level2 folder no code to change Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448791 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 thats so excellent, thanks man. also, i may have got the whole "main.htm" part wrong. what i want to do is basically have the else include (or even just echo) some kind of error message like "error" or "sorry, this doesnt exist" because this is whats going to show if the code does not work. however, on the index.php i DO want to have a display, such as a welcome page or something, but i dont think this should be part of the php include script. hopefully you know what i mean. if not, i can probably explain it more simply. Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448803 Share on other sites More sharing options...
rajivgonsalves Posted January 25, 2008 Share Posted January 25, 2008 try this out <?php $page = $_GET['page']; $course = @$_GET['course']; if (isset($page) && isset($course) && file_exists("pages/{$page}/{$course}.htm")) { include("pages/{$page}/{$course}.htm"); } else if (isset($page) && file_exists("pages/{$page}.htm")) { include("pages/{$page}.htm"); } else if ((isset($page) && !isset($course) && !file_exists("pages/{$page}.htm")) || (isset($page) && isset($course) && !file_exists("pages/{$page}/{$course}.htm"))) { include("error.htm"); } else { include ("main.htm"); } ?> make a error.htm and put it in your main folder with the error message.. hope its helpful Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448808 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 thanks again Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448810 Share on other sites More sharing options...
spacka Posted January 25, 2008 Author Share Posted January 25, 2008 sorry to "unsolve" the problem, but ive just implemented that code, and if you now goto http://69.41.171.40/arctic/vocationalacademy/index.php its not working properly. it includes main.htm which is fine, however, the include links are not working, but they DO display the error.htm file for some reason. so i guess its half working =\ Quote Link to comment https://forums.phpfreaks.com/topic/87732-im-such-a-noob-at-php-include/#findComment-448899 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.