Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Include PHP File in HTML Code

Reply  
Thread Tools
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
22-May-2007, 08:43 PM #1
Include PHP File in HTML Code
Hey all,

What I am trying to do here is I would like to have an external PHP file named "column_left.php" which will store the contents in the left column so I don't have to update every single page individually with the same information. I am using dreamweaver by the way.

I have my entire website laid out using html and CSS and all that good stuff, then I created a page and saved it as "column_left.php" and then I used the

<?php include("column_left.php"); ?> approach to enter the column in a table in my html code where I need it to be. After doing this, I saw a little "php" box in the table that I placed the code in the design view of dreamweaver, but when I load my webpage nothing shows up in that column?

I then created an "index.php" page and used all the same html code, then placed the include file in there and when I loaded the webpage the left column showed up like I wanted it to. But in the design view of dreamweaver my website looks completely different and everything is out of place.

What I want here is to be able to use my already made HTML Pages and include a simple left column for some "update" news and what not using PHP. I don't know why this isn't working though! Any help is much appreciated! THank you all!
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
22-May-2007, 09:32 PM #2
as a rule of thumb you cannot trust dreamweaver with spacing whne you have included php files.

Especially if you're php file ouptputs a bunch of html that'll affect the spacing. Dreamweaver is just smart enough to know that there is a php file there not that it'll affect the spacing in any way shape or form.


Best is to install apache and php locally and then look at the changes off of the served page
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
22-May-2007, 10:30 PM #3
Well, I bought a webhost so I have the server and all that good stuff setup already. After I add the PHP to the html in dreamweaver I save it and it autoloads the file to the server, then I test it on the web.

My Problem is that when I load the PHP in my HTML file and load it in the web it does not show up at all. I did the proper include and all for the php file, but not too sure why nothing shows. The thing is though that if I create a "index.php" file and load all of my HTML into that, then load the php include code into that as well and upload it to the server it works fine, but then the design of it in dreamweaver looks like complete crap, so I can't work on it like I use to.

Anymore help is much appreciated
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
23-May-2007, 01:18 PM #4
Ahhh I think I know what's going on.... know it all too well. (I've done this many MANY times myself)

Just during the development phase (as soon as you go live take this out) add to the top of your php code:
Code:
ini_set('display_errors','on');
What I think is happening is you have an error in your php code thats causing it to die This shoudl tell ya if you are and give you clues on what you need to do to fix it.
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
23-May-2007, 05:01 PM #5
Hmm, I believe my PHP Code is coded correctly. There isn't much to it because I am just testing it, but I think I found my problem. Apparently I need to add these lines to my .htaccess file ...

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

This will parse my PHP code in the HTML Documents. But now I have a new problem! After I add these lines to my .htaccess file and upload it to my server, my entire website is completely down and it says I have a "500 internal server error". This only occurs when I add those lines. Any ideas?? I am pretty sure that is what I need to do in order to embedd php in my html.

thanks again!
Eriksrocks's Avatar
Computer Specs
Distinguished Member with 2,198 posts.
 
Join Date: Aug 2005
Location: Minnesota
Experience: Advanced
23-May-2007, 08:36 PM #6
Just make sure that you save the main page with an extension of .php so that it will parse the PHP and you are good.
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
24-May-2007, 04:37 PM #7
Yes, but wont that just simply parse the php in the main page and not the other pages that I need it to be parsed in?
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
24-May-2007, 05:00 PM #8
Each page that has php code in it (<?php ?>) needs to have a .php extension.
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
24-May-2007, 05:00 PM #9
naming a file .php tells the server that it needs to parse the php.

otherwise it'd look at
Code:
<?php
require_once "somefile.php";
?>
and not know what to do.

The require_once/require/include functions act just as if you yourself had taken all the contents of the file and put them inline.
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
24-May-2007, 05:10 PM #10
Quote:
Originally Posted by MMJ
Each page that has php code in it (<?php ?>) needs to have a .php extension.
I was told that you could parse the php into an HTML document using this code.

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

You have to put the code in the .htaccess file. I've read this on several websites, not so sure how credible they are? But that is what I hear you can do. However, when I do this and save the .htaccess file to my server I get an internal server error 500. :-/ not real sure why.

Also, when I change my page to .php my entire template gets screwed up in the design view of dreamweaver... I can't design when it looks completely different then what I think im designing lol. Any ideas?
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
24-May-2007, 05:13 PM #11
Quote:
Originally Posted by r3drock3t88
I was told that you could parse the php into an HTML document using this code.

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

You have to put the code in the .htaccess file. I've read this on several websites, not so sure how credible they are? But that is what I hear you can do. However, when I do this and save the .htaccess file to my server I get an internal server error 500. :-/ not real sure why.

Also, when I change my page to .php my entire template gets screwed up in the design view of dreamweaver... I can't design when it looks completely different then what I think im designing lol. Any ideas?
You can do that but you shouldn't because than each file will be parsed for php which would reduce performance.

If you want to zip whatever you have and post it here.
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
24-May-2007, 05:46 PM #12
Hey MMJ, Thanks for the suggestions. I guess I'll go with your approach since performance is a major factor. I'm in no rush to have the website finished, So I don't mind starting over. It's all a learning experience . Thanks for the offer too! I appreciate it. I will just restart everything and redesign my website since my template keeps getting all funky. And I will save all my pages as .php ... Now I just have to learn how to have a members login section! If you'd like to help me out with that, it would be much appreciated If you get the time that is, thanks in advance!
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
25-May-2007, 07:33 AM #13
Okay, no prob.

Did the includes work out?
r3drock3t88's Avatar
Computer Specs
Member with 272 posts.
 
Join Date: Jan 2007
Experience: Advanced
26-May-2007, 11:02 AM #14
Quote:
Originally Posted by MMJ
Okay, no prob.

Did the includes work out?
Yes sir they did, I realized why my dreamweavers design view was getting all funky. In my php included file i was adding html and css which was conflicting with the original index.php's html and css. Once I removed the html and css from my php include file, everything worked fine . Thanks a lot for helping me out, I now realize how that all works and its a good feeling fixing things! haha.

If you get time / the patience to help out a newcomber with how the login and members section workout on a website...I would be very thankful! But only if you're up for it.

Thanks in advance!
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
26-May-2007, 11:27 AM #15
I'm glad it worked out for you.

As for the login script, will you have a register page? If so you are going to need a db.

Look at this Google search:
http://www.google.com/search?q=php+login

As you can see there are lots of ready scripts out there. If you need help setting them up just post here.

Here are some good ones:
http://php.about.com/od/finishedphp1...login_code.htm
http://www.mtdev.com/2002/07/creatin...-login-script/
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:40 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.