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

Felix Bolton
Felix Bolton
2,750 Points

redirection is not working?

After sumbmitting the form I'm not being redirected to the right page. When looking at this code i have personlised a few of the values etc. meaning it won't look exactly as it does in the video. But I still don't understand why it isn't working. Any help would be greatly appreciated.


$name = $_POST["name"];
$email = $_POST["email"];
$house = $_POST["house"];
$order = $_POST["order"];
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "House: " . $house . "\n";
$email_body = $email_body . "Order: " . $order;

// TODO: Send email  

header("Location: order-thanks.php");


5 Answers

order-thanks.php definitely exists and is at the root of your site?

Felix Bolton
Felix Bolton
2,750 Points

Andrew it's definitely exists and is a root of my site

What happens when you do click submit? Nothing? Or sent somewhere else?

Felix Bolton
Felix Bolton
2,750 Points

after pressing submit i'm taken to http://www.noodleseller.com/order-process.php which is what the code i just posted is running on.

Try the full http address, in case it's a path issue on live server.

So it seems that your form process is referring to itself and not processing the input fields. I would check the HTML codes. My best guess is the <button > tag is causing the problem. Assuming that you are using < button > </ button >

Try changing to

<input type="submit" value="submit" />

If that doesn't do it than I am not sure. But at time I think this may fix the problem using input. Hope that helps. Good luck.

Hi Felix,

Do you have those <pre> tags in your file or did you just put them here thinking you needed them in the forum?

That would prevent the redirect from working. Any output before header will prevent it from working.

Is that your entire order-process.php file? Do you have a blank line or any whitespace before your opening php block <?php ?

you solved my problem thank you... I had a space before my <?php