Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 2, 2006, 06:28 AM   #1
cooknwitha
macrumors 6502a
 
cooknwitha's Avatar
 
Join Date: May 2005
Location: London
New to PHP - very basic question.

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!
__________________
13" Macbook Pro 2.9GHz, 8GB RAM, 750GB HD
cooknwitha is offline   0 Reply With Quote
Old Feb 2, 2006, 06:34 AM   #2
Mitthrawnuruodo
Demi-God (Moderator)
 
Mitthrawnuruodo's Avatar
 
Join Date: Mar 2004
Location: Bergen, Norway
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 Code:
<?php include("header.php"); ?>
and not
PHP Code:
<? 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 Code:
<?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...
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed.
Mitthrawnuruodo is offline   0 Reply With Quote
Old Feb 2, 2006, 06:47 AM   #3
cooknwitha
Thread Starter
macrumors 6502a
 
cooknwitha's Avatar
 
Join Date: May 2005
Location: London
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.
__________________
13" Macbook Pro 2.9GHz, 8GB RAM, 750GB HD
cooknwitha is offline   0 Reply With Quote
Old Feb 2, 2006, 07:00 AM   #4
Mitthrawnuruodo
Demi-God (Moderator)
 
Mitthrawnuruodo's Avatar
 
Join Date: Mar 2004
Location: Bergen, Norway
Taco HTML Edit 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...
__________________
Those who fail to learn history are doomed to repeat it; those who fail to learn history correctly... why, they are simply doomed.
Mitthrawnuruodo is offline   0 Reply With Quote
Old Feb 2, 2006, 07:08 AM   #5
cooknwitha
Thread Starter
macrumors 6502a
 
cooknwitha's Avatar
 
Join Date: May 2005
Location: London
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!
__________________
13" Macbook Pro 2.9GHz, 8GB RAM, 750GB HD
cooknwitha is offline   0 Reply With Quote
Old Feb 2, 2006, 12:24 PM   #6
whocares
macrumors 65816
 
whocares's Avatar
 
Join Date: Oct 2002
Location: :noitаɔo˩
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).
But this is maybe the next lesson.
__________________
InvisiSig™:
"The day Microsoft makes something that doesn't suck is the day they start making vacuum cleaners." -Unknown
"And it eats 8088s for breakfast." -Steve Jobs
whocares is offline   0 Reply With Quote
Old Feb 3, 2006, 12:45 AM   #7
cooknwitha
Thread Starter
macrumors 6502a
 
cooknwitha's Avatar
 
Join Date: May 2005
Location: London
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 Code:
<?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.
__________________
13" Macbook Pro 2.9GHz, 8GB RAM, 750GB HD
cooknwitha is offline   0 Reply With Quote
Old Feb 3, 2006, 12:59 AM   #8
zimv20
macrumors 601
 
zimv20's Avatar
 
Join Date: Jul 2002
Location: chicago
Quote:
Originally Posted by cooknwitha
Then it just takes that code and puts it within the content file?
yes. handy, eh?
__________________
Oct 2011: check out my band's first album @ boxsetauthentic.com
zimv20 is offline   0 Reply With Quote
Old Feb 3, 2006, 01:13 AM   #9
cooknwitha
Thread Starter
macrumors 6502a
 
cooknwitha's Avatar
 
Join Date: May 2005
Location: London
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....
__________________
13" Macbook Pro 2.9GHz, 8GB RAM, 750GB HD
cooknwitha is offline   0 Reply With Quote
Old Mar 8, 2006, 10:04 AM   #10
selski
macrumors newbie
 
Join Date: Mar 2006
how do i post a message

Quote:
Originally Posted by cooknwitha
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!

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 is offline   0 Reply With Quote
Old Mar 9, 2006, 12:12 AM   #11
rendezvouscp
macrumors 68000
 
Join Date: Aug 2003
Location: Long Beach, California
Send a message via AIM to rendezvouscp
Quote:
Originally Posted by selski
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
__________________
Santa Rosa 2.4 15" Matte MacBook Pro
Iron Money
rendezvouscp is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
New to MobileMe - Email syncing question. thereitis iPhone 3 Jul 1, 2009 05:43 PM
new to mac - PS Elements questions 615bride Digital Photography 3 Apr 19, 2009 12:44 PM
New to Mac - Few basic Qs CaptainCocoPop Windows, Linux & others on the Mac 17 Nov 26, 2008 09:15 PM
Yes, brand new to Mac - a few questions probably useful to anyone! WirelessInn Mac Basics and Help 34 Jun 23, 2007 08:03 PM
New to Apple - Very Disappointed cb31 Mac Pro 73 Jul 9, 2006 10:36 AM


All times are GMT -5. The time now is 02:28 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC