Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Adding a Contact Form Working with Get Variables

Matthew Smart
Matthew Smart
12,567 Points

Dont understand this code

<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?> <p>Thanks for the email! I’ll be in touch shortly!</p> <?php } else { ?>

why is there ending php tags when the if statement is not even finished.

can you not have any html elements inside the php or something?

1 Answer

Basically the text between the the first closing PHP tag and then the Opening for the else tag is only displayed to the user if the condition is met. This text could be any kind of HTML (which includes tags like <p></p>) which are not valid PHP and so can't be included inside the PHP Tag.

When working with PHP it's really important to keep in mind that the code is evaluated on the server upon page request, which generates the page and sends it to the user as plain html. The user/browser never sees any of the PHP. You could just as easily not close the PHP tag and use an Echo statement instead to spit out your HTML if the condition is true. But personally I find the above method much easier and neater!

Edit: Markdown fail. Backticks needed to show code tags!