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 Working with Get Variables

Page does not display thank you message. Shows form after submission too.

When I submit the page it should give me the "thank you" message. However it does not do this and just shows the contact form again. Any thoughts?

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST"){

$name = $_POST["name"]; $email = $_POST["email"]; $message = $_POST["message"]; $email_body = ""; $email_body = $email_body . "Name: " . $name . "<br>"; $email_body = $email_body . "Email: " . $email . "<br>"; $email_body = $email_body . "Message: " . $message;

// TODO: Send Email

header("location: contact.php?status=thanks");

exit;

}

?>

<?php

$pageTitle = "Contact Mike"; $contact_on = TRUE;

include('includes/header.php');?>

<div class="section page">

   <div class="wrapper">
       <h1>Contact</h1>

       <?php if (isset($_GET["STATUS"]) and $_GET["STATUS"] == "thanks"){ ?>

       <p>Thank you for your email</p>

<?php } else { ?>

       <p>I&rsquo;d love to hear from you! Complete this form to send me an email.</p>

                <form method="post" action="contact.php">

                    <table>
                       <tr>
                            <th>
                                <label for="name">Name</label>
                            </th>
                           <td>
                               <input type="text" name="name" id="name"> 
                           </td>
                        </tr>
                          <tr>
                            <th>
                                <label for="email">Email</label>
                            </th>
                           <td>
                               <input type="email" name="email" id="eamil"> 
                           </td>
                        </tr>
                          <tr>
                            <th>
                                <label for="message">Message</label>
                            </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'); ?>

I figured it out, had to make "STATUS" lowercase.

2 Answers

"STATUS" changed to "status"

Thanks for checking, the issue was in the $_GET statement.