PHP Include: Can you look at this for me please?

Hello there.

I just wrote the most minimal PHP I could figure out to see if anything connected with anything. I am not on a server; I am trying to do this inside my Windows machine.

My HTML (it has a php suffix, and which works fine otherwise) contains

<div id="kielbasa">
Anybody home?
<?php include "/includes/menu.php";?>
</div>  <!--end kielbasa-->

and in the folder where all the html and php stuff is, there’s a folder called “includes”. In that folder is just a little text

<p>
anything I try
</p>

“Anybody home?” is just to see whether the div is working and in place (it is). I can’t figure out how to connect the php to display anything after that though. The fellow who got me this far gave me some fancy server language but I stripped it down to what the kiddie pages say to do, to try to get at the basics of what’s happening.

There’s something I’m not understanding here. Would you like to give me a hand? Sorry if what I’m asking doesn’t make sense. I don’t know enough to make sense.

Thanks

MP

I’m not clear as to what or how you’re doing things.

All the paths to the files and file name spelling is correct.
You start up your localhost PHP server.
But when you open the “anybody home” file in your browser “anything I try” doesn’t show?

Remove the first / from the path.

<?php include “includes/menu.php”;?>

But when you open the “anybody home” file in your browser “anything I try” doesn’t show?

Yep.

Remove the first / from the path.

Nope.

I picked up the Dummies book and it says to write in the whole path to the inclusion starting with c: That didn’t change anything. In some of their examples they put the path in parentheses and in some of them they don’t so I tried parentheses. That didn’t change anything.

BUT…

You start up your localhost PHP server.

Uh…the WAMP has to be running even though everything’s happening inside one folder and one subfolder? Well, I fired that up. Still nada.

Tried renaming the “includes” folder to “include”, because the book said that if I did that I wouldn’t need any path at all, just the file name. Uh-Uh.

Tried copying the file into the folder right in with all the html stuff. Nope.

Now I’m wondering whether the inclusion and the “include” folder is supposed to be stored in some special other place having something to do with WAMP? I mean, even just for while I’m messing around trying to write this thing?

???

MP

What happens when you put these addresses in your browser:

http://127.0.0.1

http://localhost

In both cases they take me to a WAMP Server Configuration page, showing Apache, PHP, and MySQL versions. I doubt that they’re old; I’m just starting to mess with this stuff.

Thanks

p

Well, the file being served from localhost (or 127.0.0.1 if you prefer) is the root of your webserver. No doubt it is called index.php. You need to find out where that folder is located on your file system.

Remove or rename that file, then create a new index.php file.

Temporarily create a folder in there too, /includes and then try your experiment again.

Nope.

I did find it, I did set it aside and put in a copy of the “menu.php” file in that folder. No go.

I put a folder called “include” and “includes” in that folder and that didn’t play either. I copied that folder up a level, even with WAMP’s www folder and that didn’t work either.

I might be getting to where I have to ship this to one of you guys and pay you to fix it…Apparently other people just do this and it works, and I can’t.

MP

You’ll get nowhere with this if you do not get to the bottom of the problem.

index.php


<?php


echo '<p>This is the index file</p>';

include './menu.php';


?>

menu.php


<?php
echo '<p>This is my menu</p>';
?>

Put them both in your web root directory and see if that works when you load index.php

Ooh, I got it.

Thanks, Cups. I won’t detail what I was doing wrong, because it was profoundly dumb and although I’m accustomed to that, sometimes other people aren’t.

Thanks so much.

Mp

No, we all felt exactly the same level of dumbness at some time or another (usually still on a daily basis) so don’t worry … you’re in good company.