1

For starters, I am completely new to PHP. That being said, here's my problem.

I've got a web page index.php that includes a header.php and footer.php. At the top of my index.php page I have:

<?php $pageID = 'home'; ?>

In the header.php file I have

<body id="<?php echo $pageID; ?>">

Yet when the page loads, the body tag simply looks as follows: <body id="">

Am I doing something wrong?

Thanks

1
  • You are going to need to show more code. Technically speaking, there is "nothing" wrong with that as long as the $pageID was set before you tried to echo it and was not set in a function which would not work due to SCOPE issues. Commented Aug 13, 2010 at 16:15

1 Answer 1

6

Check to make sure that you're declaring $pageID before you include header.php. If you're not doing that, header.php won't get your $pageID variable's value as your index file would only be setting it after the file is included, so it prints nothing instead.

In terms of code, check that the order of those respective commands is this:

$pageID = 'home';
// anything else that might be in between
include 'header.php';

As opposed to this:

include 'header.php';
// anything else that might be in between
$pageID = 'home';
Sign up to request clarification or add additional context in comments.

1 Comment

Ahh. Obvious. Thanks for taking the time to answer such a simple question. I'll check this as answered once the page lets me...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.