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 trialrob111
8,379 PointsWarning: Cannot modify header information - headers already sent by
I'm following along with the video instructions but get an error message instead of having the page go to the thanks.php page
Any idea what's causing it?
If I take out the header() function it works.
<?php
///var_dump($_POST);
$name = $_POST["name"];
$email = $_POST["email"];
$details = $_POST["details"];
echo "<pre>"; // this is line 8
$email_body = "Name " . $name . "\n"
. "Email " . $email . "\n"
. "Details " . $details . "\n";
echo $email_body;
echo "</pre>";
// To Do: Send Email
header("location:thanks.php"); // this is line 16
?>
Warning: Cannot modify header information - headers already sent by (output started at Test/Basic PHP Website/process.php:8) in /Test/Basic PHP Website/process.php on line 16
6 Answers
rob111
8,379 PointsMy data.php file had the following
<!--Catalog items-->
<?php
$catalog....
Make sure not to have any extra spaces or lines. I removed
<!--Catalog items-->
and it worked.
rob111
8,379 PointsThe only thing I can think off from reading this page: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php
It mentions this error might be because I have the ECHO statement before the header() function. But the instructor in the video does just that!?!
rob111
8,379 PointsAlso the PHP manual states "must be called before any actual output is sent" http://php.net/manual/en/function.header.php
rob111
8,379 PointsCan't proceed with my track. Looks like the following video tutorial tie into this file and it breaks the page. Any advice on how to troubleshoot would be appreciated. Please let me know if I should submit other related files that are being referenced if you need more info.
Baptiste BOULONNAIS
9,845 PointsHi Rob, I've had the same problem with MAMP locally. I turned outpout buffering to "On" on my php.ini file. This post was usefull :
https://teamtreehouse.com/community/form-redirect-to-thanksphp
rob111
8,379 PointsI have the same problem when using the header function on a different page / video assignment. Think these two errors are related: https://teamtreehouse.com/community/code-block-breaks-my-page