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 trialMatt English
15,719 PointsERR_TOO_MANY_REDIRECTS message on Chrome...
In the middle of this video (about 4:45 in, when we go to check if forms will submit when blank), I go to suggest.php and I get an error message. It's ERR_TOO_MANY_REDIRECTS.
Here's my code: (Note: I was having trouble in an earlier video getting the thank you page to load, so the solution seemed to be moving the header function to the top. That's why it is there and not in the same place as the video. Don't think that's causing my issue, but I could most definitely be wrong!)
<?php
header("location:suggest.php?status=thanks");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$details = trim($_POST["details"]);
if ($name == "" || $email == "" || $details = "") {
echo "Please fill in the required fields: Name, Email and Details";
exit;
}
echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Details " . $details . "\n";
echo $email_body;
echo "</pre>";
}
//To Do: Send email!
$pageTitle = "Suggest a Media Item";
$section = "suggest";
include("inc/header.php"); ?>
1 Answer
Simon Coates
28,694 Pointsyour first statement is a redirect. This should probably be placed inside a condition. Redirect should occur if your operation is successful. Left outside a condition, it'll just loop redirects. hence the message.
Matt English
15,719 PointsMatt English
15,719 PointsThank you! That was it. I'd accidentally moved the redirect outside of the condition.