ofmyst Posted August 8, 2008 Share Posted August 8, 2008 Here is my problem. I had a .html file that used <!--#include virtual="/menus/galmenu.html" --> to access two menus written in javascript. I changed the .html file to .php in order to use php to access data from mysql, which worked. However, when I changed the file extension to .php the include virtual menus no longer worked. I changed the request to <?php include ?> but that did not work either. My guess is that it is not working because the menus are written in javascript. If I am correct my question is can I structure the page in the reverse, - keep the page as a .html and include the .php somehow so that the javascript can still work? I am a complete novice so I not sure if I am asking for too much here or if I am using the right language to describe what I am trying to do. Thanks for any help. Sharon Quote Link to comment https://forums.phpfreaks.com/topic/118721-solved-use-include-to-access-php-file-for-access-to-mysql-from-a-html-file/ Share on other sites More sharing options...
deadlyp99 Posted August 8, 2008 Share Posted August 8, 2008 Try this out: <script type="javascript" src="/menus/galmenu.html"></script> Put it in the <head> tag. That is the modern way of including javascript. No need to use php, and in fact it would be wise not to. Why? because then there is less your server has to execute when the page is loaded, all the work gets done on the clients computer, yippie Quote Link to comment https://forums.phpfreaks.com/topic/118721-solved-use-include-to-access-php-file-for-access-to-mysql-from-a-html-file/#findComment-611255 Share on other sites More sharing options...
ofmyst Posted August 8, 2008 Author Share Posted August 8, 2008 Thank you for the suggestion. For some reason I could not get it to work with the javascript line. I need , or think I need, to use PHP in order to access my mysql database. I was finally able to get the menu work using <?php include ("galmenu.html") ?> HOWEVER it will only work if my menu file is in the same directory as the php file. Unfortunately, my menus are all in a file called menus. I have lots of images, etc., and so my site is divided up into many subdirectories. It would be very messy for me to move everything into the main public_html. When I change the line to <?php include ("/menus/botmenu.html") ?> it does not work. When I put the entire string in "http://www.... com/menus/botmenu.html" it doesn't work either. If it helps the file I am working with (still in working stage) is www.sharondross.com/images/tinker/tinker4.php I really appreciate the help. I keep thinking I get the problems resolved only to run into yet another road block! Quote Link to comment https://forums.phpfreaks.com/topic/118721-solved-use-include-to-access-php-file-for-access-to-mysql-from-a-html-file/#findComment-611287 Share on other sites More sharing options...
wildteen88 Posted August 8, 2008 Share Posted August 8, 2008 <?php include ("/menus/botmenu.html") ?> it does not work. When I put the entire string in "http://www.... com/menus/botmenu.html" Because your include starts with a forward slash, this tells PHP to load the requested file from the root of the filesystem (eg C:\) not the root of your websites root directory. I'd change this line <?php include ("/menus/botmenu.html"); ?> to <?php include $_SERVER['DOCUMENT_ROOT'] . '/menus/botmenu.html'; ?> Now PHP will include the file from your websites root directory. Quote Link to comment https://forums.phpfreaks.com/topic/118721-solved-use-include-to-access-php-file-for-access-to-mysql-from-a-html-file/#findComment-611451 Share on other sites More sharing options...
ofmyst Posted August 8, 2008 Author Share Posted August 8, 2008 Thank you! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/118721-solved-use-include-to-access-php-file-for-access-to-mysql-from-a-html-file/#findComment-611808 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.