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 trialJames Houston II
1,812 PointsContact page will not redirect loops back to contact page
Here is my code I cannot understand why only the else code is executed it jumps past the thank you redirect
<?php
if ($_SERVER["REQUEST_METHOD"]=="Post") {
$name = $_POST ["name"];
$email = $_POST ["email"];
$message = $_POST ["message"];
$email_body="";
$email_body= $email_body . "Name:" .$name ."\n";
$email_body= $email_body . "Email: ".$email ."\n";
$email_body= $email_body . "Message: " .$message;
//TODO: send E-mail
//not part of header file this header is for http about how site and brwoser communicate
header("Location: contact.php?status=thanks ");
exit;
}
?><?php
$pageTitle = "Contact Mike";
$section = "contact";
include ('includes/header.php')?>
<div class="section page">
<div class="wrapper">
<h1>Contact</h1>
<?php if(isset($_GET["status"]) AND $_GET["status"] == "thanks"){?>
<p>Thanks for the e-mail! I’ll be in touch shortly</p>
<?php } else { ?>
<p> I’d love to hear from you! Complete the form and send me an e-mail.</p>
<form method="post" action="contact.php">
<table>
<tr>
<th>
<lable for="name">Name </lable>
</th>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<tr>
<th>
<lable for="email">Email </lable>
</th>
<td>
<input type="email" name="email" id="email">
</td>
</tr>
<tr>
<th>
<lable for="message">Message</lable>
</th>
<td>
<textarea name="message" id="message"> </textarea>
</td>
</tr>
</table>
<input type="submit" value="Send">
</form>
<?php } ?>
</div>
</div>
<?php include('includes/footer.php'); ?>
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi James,
In this code here:
if ($_SERVER["REQUEST_METHOD"]=="Post") {
you don't have "Post" in all uppercase letters. Try changing that and see if it helps.
Also, you have a trailing space after 'thanks' here:
header("Location: contact.php?status=thanks ");
I'm not sure if that would cause any problem but I would remove it.
James Houston II
1,812 PointsThank you it works