Jump to content

PHP include() not diplaying contents


rsrwebs

Recommended Posts

I saved the header contents as a PHP file, and I put the include code into my index.htm page with the correct path name.

 

In order to use PHP includes, your main page needs to use the .php extension. In this case, you'll need to change index.htm to index.php.

 

Okay, so in order for this set-up to function, everything has to be the PHP extension?

Link to comment
Share on other sites

I looked over your code a bit, and I have to admit I'm a bit confused... Maybe it's that you haven't posted the entire files, but they seem to be set up wrong. For example, with those two files you have two sets of body tags... it just isn't what I would expect.

 

For example, here is a brief example showing a php include used to include navigation elements:

 

Index.php file:




title















 

nav.php:

>
</pre>
<ul id="nav">
nav item
nav item
nav item
nav item
</ul>

Link to comment
Share on other sites

You can put PHP includes inside other php includes; but your code doesn't have the include function; perhaps it should be like this:-

PHP INCLUDES





 

and footer.inc file has only this:-

 

print $secret_password;
?>

 

then the first page will show the word fish inside the p tags after two php codes. (I haven't followed all the previous posts so I'm just showing how it could work).

Edited by Wickham
Link to comment
Share on other sites

(A page can only contain one set of body tags, and html tags for that matter, isn?t that right?).

Correct.

 

I noticed that in order for the declared variable contained in footer.inc.php to work, it must be wrapped in PHP tags. But that doesn't make any sense to me because if I were to put that section straight into my_page.php without using the include function, it would generate an error (as expected) because there would be PHP tags wrapped in PHP tags

If you are using PHP, anything that you expect the server to understand/render as PHP HAS to be within PHP tags. If you have two separate files, with two separate blocks of PHP, they'll each need their own sets of PHP tags in order for the server to properly understand it. I understand that you are including a file, so you might expect that the first set of PHP tags could work for both files, but the server can't assume that the included file necessarily contains PHP code -- it could contain javascript, regular html, or anything.

Link to comment
Share on other sites

Are you running this on a server (either on a server on your local machine or uploaded to your web hosting)? If you have uploaded it to your web host, are you sure your host supports PHP?

 

If you have posted it to your hosting, post a link or send me a private message with the link?

 

I know for a fact that my server is running PHP 5.0. I'm unsure why it won't load.

Link to comment
Share on other sites

...This stuff is beginning to make less and less sense to me...
If by "stuff" you're referring to PHP in general, take heart, rswebs. Have you viewed the beginner PHP videos by Stef Mischook (frog)? They're the most easy to understand tutorials on PHP I've ever come across. I have tried learning PHP before and quit because it just seemed too overwhelming at the time but after watching Stef's videos, I have resolved to learn as much as I can about it.
Link to comment
Share on other sites

...This stuff is beginning to make less and less sense to me...
If by "stuff" you're referring to PHP in general' date=' take heart, rswebs. Have you viewed the beginner PHP videos by [b']Stef Mischook (frog)[/b]? They're the most easy to understand tutorials on PHP I've ever come across. I have tried learning PHP before and quit because it just seemed too overwhelming at the time but after watching Stef's videos, I have resolved to learn as much as I can about it.

 

Hey, thank you! Where can I find these tutorials? :)

Link to comment
Share on other sites

...This stuff is beginning to make less and less sense to me...
If by "stuff" you're referring to PHP in general' date=' take heart, rswebs. Have you viewed the beginner PHP videos by [b']Stef Mischook (frog)[/b]? They're the most easy to understand tutorials on PHP I've ever come across. I have tried learning PHP before and quit because it just seemed too overwhelming at the time but after watching Stef's videos, I have resolved to learn as much as I can about it.

 

Hey, thank you! Where can I find these tutorials? :)

Here's the entire list of the tutorials. You'll notice that not all of them can be linked to from that page. Most of others can be found at Idea22.com with slightly different titles in some instances but they are the same videos. I'll post the direct links when I get a chance.

 

(EDITED to correct original link to the beginners PHP tutorial.)

Edited by abajan
Link to comment
Share on other sites

  • 3 weeks later...

<?php is the suggested method. Not all servers allow short_tags. . since it conflicts with the XML tag.

 

Another thing, to add to what falkencreative posted above, an "included" file is always assumed to contain html and is parsed as such unless you add the php tokens. (<?php ... code here ... ?>)

Edited by jlhaslip
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...