PDA

View Full Version : New to PHP - very basic question.




cooknwitha
Feb 2, 2006, 06:28 AM
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

<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
<? include("header.php"); ?>
<h1>This is the first page</h1>
<? include("footer.php"); ?>


Footer File

<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! :o



Mitthrawnuruodo
Feb 2, 2006, 06:34 AM
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 include("header.php"); ?>
and not
<? include("header.php"); ?>
but I'm not sure it will help Dreamweaver.

(I just use TextWrangler (http://www.barebones.com/products/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 ?>
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... :)

cooknwitha
Feb 2, 2006, 06:47 AM
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.

Mitthrawnuruodo
Feb 2, 2006, 07:00 AM
Taco HTML Edit (http://tacosw.com/htmledit/) supports PHP preview, if you want something a with a bit more functionality than a text editor... :)

Both that and TextWrangler are free... and highly recommended...

cooknwitha
Feb 2, 2006, 07:08 AM
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!

whocares
Feb 2, 2006, 12:24 PM
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 (http://www.w3.org/TR/html4/struct/global.html#version-info) or here (http://www.w3.org/TR/xhtml1/#normative)). :eek: ;)
But this is maybe the next lesson. :)

cooknwitha
Feb 3, 2006, 12:45 AM
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:


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


and if the content files calls it up:

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


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

zimv20
Feb 3, 2006, 12:59 AM
Then it just takes that code and puts it within the content file?
yes. handy, eh?

cooknwitha
Feb 3, 2006, 01:13 AM
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....

selski
Mar 8, 2006, 10:04 AM
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

<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
<? include("header.php"); ?>
<h1>This is the first page</h1>
<? include("footer.php"); ?>


Footer File

<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! :o


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

rendezvouscp
Mar 9, 2006, 12:12 AM
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