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 trialSamy Basset
11,862 PointsCan'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’ll be in touch shortly.</p>
<?php } else { ?>
//else condition
<?php } ?>
4 Answers
Samy Basset
11,862 PointsI 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!
Nam Pham Duong Nhat
Courses Plus Student 1,184 PointsIn PHP, "AND" operator must be used two ampersand like this : && Try it yourself !!
Robert Richey
Courses Plus Student 16,352 PointsAND is a lower precedence operator than &&, but otherwise still valid.
Samy Basset
11,862 PointsIt 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.
Samy Basset
11,862 PointsThat's the funny part Robert Richy, it just shows the contact form again.
Robert Richey
Courses Plus Student 16,352 PointsDo 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.
Robert Richey
Courses Plus Student 16,352 PointsRobert Richey
Courses Plus Student 16,352 PointsHi 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.