Hi All,I am trying to learn PHP and am going through David Powers' PHP Solutions. I am getting the hang of things and finally beginning to understand after going through Lynda.com and a bunch of online resources. Now I am tackling this book and I am confused about why something doesn't work. It is from pg 82-83 of his book and involves the use of an include to set the page title. All the other includes from this chapter work fine and so does this one - but only if a suggested isset statement is used. What I am having trouble with is why this is needed to make it work. The include code says to change the title to the filename minus the extension and has a condition that says if the title pages is index set $title = home. Unless you use the isset statement (<?php if (isset($title)) {echo "—{$title}";} ?> it will not work. Why is that? If there was a problem with the include it wouldn't work at all, yet when the isset statement isn't there, it doesn't work. Any ideas?

Thanks ahead.

cpradio
—
2012-08-20T18:31:21Z —
#2

Can you show us the code where you are defining the value of $title? You made mention of $title = home, but that isn't valid PHP, so I'd like to see exactly how you are setting the value of $title.

Then you would need isset because $title isn't defined unless you are on the index page and so the variable would not be set in all situations.

jskintauy
—
2012-08-20T22:51:38Z —
#6

Thanks for the cool reply. When I comment out the isset on my server using the code that I showed you it doesn't work.I am going to try this on a different server and see if it makes a difference (I am not experienced enough to know how much difference this will make, but I might learn something. I like the second set of code and understand why isset would be needed. Thanks for that, it helps.

cpradio
—
2012-08-20T22:53:21Z —
#7

When you commented it out, did you leave it as

<?php echo "- $title"; ?>

jskintauy
—
2012-08-22T20:33:40Z —
#8

cpradio said:

When you commented it out, did you leave it as

php<?php echo "- $title"; ?>

jskintauy
—
2012-08-22T20:35:02Z —
#9

Yes. The dash works fine....

John_Betong
—
2012-08-23T00:53:43Z —
#10

jskintauy said:

Yes. The dash works fine....

The code you supplied is missing a double-quote:

<!-- <meta charset=utf-8"> -->
<meta charset="utf-8">

Please explain what you mean when you say "...something doesn't work."

Also please show the code that is working and also exactly how you commented out the isset statement.

Also please include your code in block php tags (without the space which follows the leading square bracket):