Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cooknwitha

macrumors 6502a
Original poster
May 5, 2005
562
0
London
I've tried finding an answer for this but to no avail. Maybe it's just too basic.

I've decided to finally learn some basic php to use with my website. The dynamic bits of the website I want are:

1) Header
2) Side menu
3) Footer.

So, VERY basic. Now, when I enter what I consider the most basic code into Dreamweaver MX 2004, it gives me the yellow code warning saying I'm wrong. I haven't even started with the sidebar yet! This is what the three files contain:

Header File
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>This is a test page</title>
</head>
<body>
<p>This is a header</p>

Content File
Code:
<? include("header.php"); ?>
<h1>This is the first page</h1>
<? include("footer.php"); ?>

Footer File
Code:
<p>This is a footer</p>
</body>
</html>

Now that is EXACTLY what the files contain. The yellow error comes up in regards to the footer code. If I use the readfile command, it's happy but if I use include or require I get told my code is bad.

Is it? Or is Dreamweaver wrong? If I view the page in IE, Safari or Firefox it works fine but I don't like the idea of starting off with wrong code.

I know this is the most basic of questions but I can't find an answer online that makes sense. Like I said, I just started learning! :eek:
 
The code looks fine, and Dreamweaver isn't the best at rendering php, so I'm not sure...

You could try to use the full
PHP:
<?php include("header.php"); ?>
and not
PHP:
<? include("header.php"); ?>
but I'm not sure it will help Dreamweaver.

(I just use TextWrangler for all my php scripting, I think Dreamweaver is a bit overkill unless you want to use templates and set up a site for Contribute editing ;)).

I also always insert an empty
PHP:
<?php  ?>
on top of all php files, like your header and footer, even if they doesn't contain any actual php code, just to kickstart the server, sort of speak... but I don't think that's really necessary... just a habit of mine... :)
 
Thanks for that.

Dreamweaver is overkill, I agree. And it often over-complicates things! I'm just used to doing my html and css in it but I'm starting to discover php isn't its forté.

Well, I'm content that I'm not wrong. Thanks for that. I feel better now.
 
Thanks Mitthrawnuruodo!

I'm a whore for freebies and Taco HTML Edit looks perfect. I have enough confidence in my HTML now to not require a "see as you type" situation and this looks perfect.

Thanks!
 
You may also consider using require() instead of include(). This will force your "content" PHP script to die if it can't include the header and footer.

This would be consistent with many of your required html tags (<html>, <head>, <title>, <body> to name them all) being in included files. If the files arn't included, well the html page doesn't really exist ;)
This will be totally transparent for you and your visitors, and will help debugging (say, you forget to ftp the header and footer...).


Also, don't forget document type declaration (here or here). :eek: ;)
But this is maybe the next lesson. :)
 
Yes, upon further reading I've decided require () is the better way to go. And I had included the HTML declarations but not in this post. So I kind of lied. Not everything was included. :)

On Day 2 of learning php, I just want to get this right in my head. php is really just saying "go to this file and enter this info here" so, in theory, a php file could nothing but the following code:

Code:
<h1> I'm here for the sake of it</h1>

and if the content files calls it up:
PHP:
<?php require("file.php"); ?>

Then it just takes that code and puts it within the content file? So php files can contain ANYTHING no matter how small?

So using the above example, if I wanted to change the the heading to say:

Code:
<h1>This is new</h1>

Then I'd just change that small, measly php file and all would be good?

Am I on the right track? Php.net I just found too overwhelming! So I'm just taking little baby steps for now.
 
Hooray!

First CSS and now php! My "now learn this" exercises are proving fantastic! Sadly my 100+ portfolio website would have benefitted greatly from php. Ah well, I'll fix that up one rainy day....
 
how do i post a message

cooknwitha said:
I've tried finding an answer for this but to no avail. Maybe it's just too basic.

I've decided to finally learn some basic php to use with my website. The dynamic bits of the website I want are:

1) Header
2) Side menu
3) Footer.

So, VERY basic. Now, when I enter what I consider the most basic code into Dreamweaver MX 2004, it gives me the yellow code warning saying I'm wrong. I haven't even started with the sidebar yet! This is what the three files contain:

Header File
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>This is a test page</title>
</head>
<body>
<p>This is a header</p>

Content File
Code:
<? include("header.php"); ?>
<h1>This is the first page</h1>
<? include("footer.php"); ?>

Footer File
Code:
<p>This is a footer</p>
</body>
</html>

Now that is EXACTLY what the files contain. The yellow error comes up in regards to the footer code. If I use the readfile command, it's happy but if I use include or require I get told my code is bad.

Is it? Or is Dreamweaver wrong? If I view the page in IE, Safari or Firefox it works fine but I don't like the idea of starting off with wrong code.

I know this is the most basic of questions but I can't find an answer online that makes sense. Like I said, I just started learning! :eek:


Hi can you tell me how i can enter my own post? i'm new here and not sure how to do this. thank you selena :)
 
selski said:
Hi can you tell me how i can enter my own post? i'm new here and not sure how to do this. thank you selena :)

I know I'm not selena, but here at MacRumors? There's a "Post Reply" at the bottom of each thread that's open (once in a while a thread gets lock because there has been some nonsense).
-Chasen
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.