Alex1646 Posted February 20, 2011 Share Posted February 20, 2011 Im trying to create a php template. What I want to do is take in GET data saying what page I am on, then include that in the template. THe trouble is I cant get the damn thing to work, it keeps saying the file does not exist! Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div class="content"> <?php $page = $_GET['page']; $path = '/inc ' .$page .".php"; if(!isset($page)) { die('No Page Specified'); } if (file_exists($path)) { include($path); } else { die('Does not exsist!'); } ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/ Share on other sites More sharing options...
cunoodle2 Posted February 20, 2011 Share Posted February 20, 2011 My bad..my post was wrong.I'm on a mobile device and hard to work with. Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177271 Share on other sites More sharing options...
Alex1646 Posted February 20, 2011 Author Share Posted February 20, 2011 No offence. But I still need help. Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177285 Share on other sites More sharing options...
ale8oneboy Posted February 20, 2011 Share Posted February 20, 2011 On this line: $path = '/inc ' .$page .".php"; I notice there is a space after "/inc". Does the file to be included have a space in the file name? Is the file in the root of your application? Try to echo out what the path it's concatenating is and verify that the path is correct. It may be just as simple as that space causing issues. Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177291 Share on other sites More sharing options...
Alex1646 Posted February 20, 2011 Author Share Posted February 20, 2011 There is no space in the file name. The file is called 'inc' without the quotes. I keep getting the same error. Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177296 Share on other sites More sharing options...
ale8oneboy Posted February 20, 2011 Share Posted February 20, 2011 If there not a space in the file name then that's your issue. Remove the space on line where it creates the path. The way the script is now it's adding a space. Try changing: $path = '/inc ' .$page .".php"; to $path = '/inc' .$page .".php"; Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177297 Share on other sites More sharing options...
cunoodle2 Posted February 21, 2011 Share Posted February 21, 2011 Echo $path; Does it look right? Quote Link to comment https://forums.phpfreaks.com/topic/228304-having-trouble-with-include-get-statement-help/#findComment-1177389 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.