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 Redirecting After a Form Submission

header() method has no effect

I've tried to use different examples of header("Location: name.php");, but nothing seems to work. I still get the contact-process.php page. What might be wrong?

3 Answers

Can you post your code?

https://teamtreehouse.com/forum/posting-code-to-the-forum

header doesn't work if you output any html before it. Having a blank line before your opening php tag is considered output and would be one cause on why this is not working.

I figured out the problem: I had an echo statement right before the header() function. I'm really new to PHP, so that didn't seem wrong at first :) Thank all of you for help! I really appreciate it.

Samiruddin Syed
Samiruddin Syed
3,136 Points

Th header function works only if you write it correctly, notice the "L" in your header location is in uppercase letters. It should be header("location:name.php");

Try to avoid spaces where they aren't required :)

Hope that helps.

The examples on this page http://www.php.net/manual/en/function.header.php show it with both an uppercase 'L' and a space after the ':'

Samiruddin Syed
Samiruddin Syed
3,136 Points

Can you post the code of the page here ?