Natt Posted July 30, 2012 Share Posted July 30, 2012 Please help. I am going crazy with the include function. I have not been able to succesfully include any files. I have even tried to include files using examples provided in the index file (script 3.4) and I cannot get the header and footer to be included. i) Has anyone else experienced this problem II) What is the effective way to debug, or locate the wourse of the problem (Remember that I have copy-pasted the files, adjusted the directory locations and still a deadend. Will appreciate any help or directions to get this over. I cant move on as this section is very important to me. Natt Link to comment Share on other sites More sharing options...
HartleySan Posted July 30, 2012 Share Posted July 30, 2012 I've had problems here or there with including files (as everyone has), but have always been able to resolve them. Perhaps if you could give us an example of your code and the directory structure, that would help. Thanks. Link to comment Share on other sites More sharing options...
Paul Posted July 30, 2012 Share Posted July 30, 2012 Natt, Hi. What is the error message that comes up? Or are they just 'missing'? Paul Link to comment Share on other sites More sharing options...
Paul Posted July 30, 2012 Share Posted July 30, 2012 Oops, sorry HartleySan & Natt, message crossed. Link to comment Share on other sites More sharing options...
Natt Posted July 30, 2012 Author Share Posted July 30, 2012 Hi; Thanks for the reply. I have just copies the files in Chapter 3 viz. Header HTML - Script 3.2, Footer HTML - script 3.3 and then called them in the PHP file, script 3.4. The files are; Header; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $page_title; ?></title> <link rel="stylesheet" href="includes/style.css" type="text/css" media="screen" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <div id="header"> <h1>Your Website</h1> <h2>catchy slogan...</h2> </div> <div id="navigation"> <ul> <li><a href="index.php">Home Page</a></li> <li><a href="calculator.php">Calculator</a></li> <li><a href="dateform.php">Date Form</a></li> <li><a href="#">link four</a></li> <li><a href="#">link five</a></li> </ul> </div> <div id="content"><!-- Start of the page-specific content. --> <!-- Script 3.2 - header.html --> Footer: <!-- Script 3.3 - footer.html --> <!-- End of the page-specific content. --></div> <div id="footer"> <p>Copyright © <a href="#">Plain and Simple</a> 2007 | Designed by <a href="http://www.edg3.co.uk/">edg3.co.uk</a> | Sponsored by <a href="http://www.opendesigns.org/">Open Designs</a> | Valid <a href="http://jigsaw.w3.org/css-validator/">CSS</a> & <a href="http://validator.w3.org/">XHTML</a></p> </div> </body> </html> PHP Body content file: <?php # Script 3.4 - index.php $page_title = 'Welcome to this Site!'; include ('includes/header.html'); ?> <h1>Content Header</h1> <p>This is where the page-specific content goes. This section, and the corresponding header, will change from one page to the next.</p> <p>Volutpat at varius sed sollicitudin et, arcu. Vivamus viverra. Nullam turpis. Vestibulum sed etiam. Lorem ipsum sit amet dolore. Nulla facilisi. Sed tortor. Aenean felis. Quisque eros. Cras lobortis commodo metus. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit vitae, cursus sed, arcu lorem ipsum dolor sit amet.</p> <?php include ('includes/footer.html'); ?> When I run the index file, this is what i get: Content Header This is where the page-specific content goes. This section, and the corresponding header, will change from one page to the next. Volutpat at varius sed sollicitudin et, arcu. Vivamus viverra. Nullam turpis. Vestibulum sed etiam. Lorem ipsum sit amet dolore. Nulla facilisi. Sed tortor. Aenean felis. Quisque eros. Cras lobortis commodo metus. Vestibulum vel purus. In eget odio in sapien adipiscing blandit. Quisque augue tortor, facilisis sit amet, aliquam, suscipit vitae, cursus sed, arcu lorem ipsum dolor sit amet. Link to comment Share on other sites More sharing options...
HartleySan Posted July 30, 2012 Share Posted July 30, 2012 No problem, Paul. Thanks for helping. Natt, thanks for posting that, but what's your actual directory structure? Everything depends on that. Are header.html and footer.html in the includes directory under the directory that the main PHP script is in? Link to comment Share on other sites More sharing options...
Natt Posted July 31, 2012 Author Share Posted July 31, 2012 Hi; my index file is in the directory; C:\ . . \Natts Files\E-Commerce\Tutorials\PHP6&MySQL5 While the header, footer and style files are in the directory; C:\ . . \Natts Files\E-Commerce\Tutorials\PHP6&MySQL5\includes So from the directory position, relatively, I think that this should work. However the include function doesnt get the content of the included files. Any ideas about what I may not be seeing? Natt Link to comment Share on other sites More sharing options...
HartleySan Posted July 31, 2012 Share Posted July 31, 2012 Just to confirm, you are running the PHP script on a (virtual) server and everything outside of the include files is loading fine, right? Does the CSS style sheet load okay? Is it just the header and footer HTML files that aren't loading? Link to comment Share on other sites More sharing options...
Natt Posted July 31, 2012 Author Share Posted July 31, 2012 Hi; First I am not sure what you mean by a virtual server! The CSS sheet is called in the header file. So if the header isnt working, then there is no way to confirm if the CSS is. However, if I load the header file by itself, then the CSS is OK. So it is the header/footer files that arent being called in the php file that refers to the two files. If you have the book, PHP6 and MySQL five, you can see the examples. I have just copied them as they are in the boon and adjusted/created the directories as directed but the includes arent just being recognized. By the way I am carrying out the tests on my computer - a mac, running on windows parallels. When upload everything to a URL test site, I only get a blanc page. When i run it on my machine then I get the results I have displayed above. I still just cant figure it out. I have tired other examples of includes I have found on the internet but non seem to work. Could it be my setup? Natt Link to comment Share on other sites More sharing options...
Natt Posted July 31, 2012 Author Share Posted July 31, 2012 Hi; I managed to solve this problem by trial and error. I decided to load all my files into a test site (with URL) and voila, the include worked. I also adjusted the style sheet and it too worked. I cant understand why it aint working when I run it from my computers storage location. Thanks to the guys who offered advice. Natt Link to comment Share on other sites More sharing options...
HartleySan Posted July 31, 2012 Share Posted July 31, 2012 PHP scripts must run on a server. As such, if you want to run them locally, you need to install a virtual server using XAMPP or the like. Larry recommends XAMPP as it's free, and most people on these boards, including myself, use it. Link to comment Share on other sites More sharing options...
Natt Posted July 31, 2012 Author Share Posted July 31, 2012 Thank you for that. I think that this must be the solution. I will try to implement a local virtual server. Thank you. Natt Link to comment Share on other sites More sharing options...
Recommended Posts