"Object-Oriented Swift" was retired on May 31, 2020.

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

Can't find the error in my code. php course - Working with Get Variables.

Hi, i've been looking to find the error for a while now, and I just can't find it. Help would be great.

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

//else condition

<?php } ?>

Hi Samy,

What is the error you're receiving? I created a quick prototype page with your code and didn't get any errors - although, I removed that else condition comment, because that's outside PHP code blocks.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <a href="index.php?status=thanks">Click</a>
    <?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
            <p>Thanks for the email! I&rsquo;ll be in touch shortly.</p>
    <?php } else { ?>


    <?php } ?>
</body>
</html>

4 Answers

I found the reason why it wouldn't work

header("Location: contact.php?status=thanks!");

I added an exclamation point in the thanks status, after I removed this it worked.. Kinda stupid.

Thanks for the help guys!

In PHP, "AND" operator must be used two ampersand like this : && Try it yourself !!

AND is a lower precedence operator than &&, but otherwise still valid.

It still doesn't work though. After you fill in the form it should display the thanks message, instead it just shows the contact form again.

That's the funny part Robert Richy, it just shows the contact form again.

Do you have

header("Location: contact.php?status=thanks");

at the top of your page inside the if condition?

if ($_SERVER['REQUEST_METHOD'] == "POST") {

When you click send, it reloads the page, but because it was sent with method=post, this if condition will trigger and at the end, the header function will reload the page again, loading the $_GET variable with status = thanks.