Nothing in PHP section showing in browser

I’m doing my first assignment for my PHP class and it seems I’m in way over my head. Last week, I was able to view a few practice .php files in my browser and they were working fine. Now only the content outside of the <?php ?> brackets is showing (the html headings and whatnot) in any file I try to open. Below is the assignment I’m working on. It’s definitely a work in progress since I haven’t been able to view anything except the headings in my browser. I have no clue if any of the php actually works. I’m on a computer running Windows 7 Enterprise, I’m using XAMPP then copying my files into my school’s FTP client.

Also, when I’m in TextPad and I click “View in Web Browser,” it opens my files up in Notepad. Last week it launched them straight into IE. What am I missing here?

Dangerous Pirates body {background-color: lightblue; color: indigo; margin-left: 50px}

Dangerous Pirates

Program ID

Your Name


<?php
$pirate1 = "Cheung Po Tsai";
$pirate2 = "Bartholomew Roberts";
$pirate3 = "Anne Bonny";

define("PICTURE1", dead_men.gif);
define("PICTURE2", skull.gif);
define("PICTURE3", map.gif);

header ('content-type: image/gif');
readfile(PICTURE1);

echo "<p><h4>", $pirate1, "</h4>
One of the characters in the movie Pirates of the Caribbean: At World's End is based on Cheung Po Tsai. Cheung was mostly known because of a legend about his hidden treasure in Cheung Po Tsai Cave in Cheung Chau Island. Many tourists still visit this location trying to find hidden pirate treasure.</p>";

header ('content-type: image/gif');
readfile(PICTURE2);

echo "<p><h4>", $pirate2, "</h4>
Bartholomew Roberts was the most successful pirate the world ever knew. Rumor has it he plundered around 400 ships in his lifetime. He was born in 1682, died in 1722, and was known as Black Bart.</p>";

header ('content-type: image/gif');
readfile(PICTURE3);

echo "<p><h4>", $pirate3, "</h4>
Anne Bonny was an Irish pirate born Anne Cormac in 1697. She married pirate James Bonny when she was 16 and followed him to a pirate's hideout in New Providence. In 1720 she was on a ship when the British Navy attacked. The crew was taken to Port Royal to stand trial. Though found guilty of the crime of piracy, Anne was spared her life because she claimed to be pregnant. The fate and date of death of Anne Bonny is unknown. </p>";

?>

Hi there,

Get rid of the double-quotes and the commas surrounding your variables as a double-quoted string will display the value of the variable by default.

[php]echo “

”, $pirate1, "


One of the characters in the movie Pirates of the Caribbean: At World’s End is based on Cheung Po Tsai. Cheung was mostly known because of a legend about his hidden treasure in Cheung Po Tsai Cave in Cheung Chau Island. Many tourists still visit this location trying to find hidden pirate treasure.";[/php]

Should be:

[php]echo “

$pirate1


One of the characters in the movie Pirates of the Caribbean: At World’s End is based on Cheung Po Tsai. Cheung was mostly known because of a legend about his hidden treasure in Cheung Po Tsai Cave in Cheung Chau Island. Many tourists still visit this location trying to find hidden pirate treasure.”;[/php]

Do this same on your other parts of your code. This should fix your issues. Let me know if you have any other questions.

Thank you for the help, it’s good to know that at least my assignment is pretty much correct, but that doesn’t really address the main problem. :frowning:

As I touched on above, I can’t even get the files my instructor provided to open correctly. And after I made the corrections you suggested to my assignment, it still does not show anything within the PHP tags in the browser, only the top three headings (in the html portion outside of the php tags) appear. This is happening with all the .php files I open in my web browser…so I know I’m doing something wrong.

I have XAMPP with Apache and MySql running. I copy my completed file onto the FTP ITOS client, open it in my web browser and still get the same results as above. I feel like I’m missing a step somewhere or something is not configured correctly. Any help would be appreciated, thanks!

I don’t use XAMPP, I use EasyPHP. Anyways, I’ll try to help. For me, if I just try to open a PHP document with my browser, it will not work. I have to go to http://127.0.0.1/ in the browser. Then I can navigate the files on the server, and I must open it from there. I don’t know if XAMPP is similar, but maybe it will help.

Hi there,

At the very top of your page, above the DocType declaration, put:
[php]<?php
error_reporting(E_ALL);
?>[/php]

You will no doubt get errors relating to the header() function.

The header() function cannot be used once output has already been sent to the browser (any space or characters outside PHP tags or any sort of echo/print method within PHP).

To add images, just do:
[php]echo ‘My picture’;[/php]
or:
[php]//php code
?>
My Picture

<?php //more php code[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service