Jump to content

[SOLVED] Use include to access .PHP file (for access to mysql) from a .HTML file?


Recommended Posts

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

 

 

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 :)

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!

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.