Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Adding a Contact Form Working with Get Variables

Marc Murray
Marc Murray
4,618 Points

Contact.php now loads as a blank page

Can anyone see where I'm going wrong? I know it should be some silly error but I've tried some PHP lint tools and they say there's no syntax errors.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
echo "Name: " . $name . "</br>";
echo "Email: " . $email . "</br>";
echo "Message: " . $message;
//TODO: Send Email
header("Location: contact.php?status=thanks");
exit;
}
?>

<?php 
$pageTitle = "Contact Mike";
$section = "contact";
include ('inc/header.php'); ?>

<div class="section page">

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

<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
        <p>Thanks for the Email! Ill Be in touch shortly.</p>
<?php } else { ?>

        <p>We would love to hear from you! Complete the form to send us 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="text" name="email" id="email">
                        </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>
            </div>
        </div>
    </div>

<?php
include ('inc/footer.php') ?>

3 Answers

Your missing the } after the end of the form. (the else isn't closed off)

Alena Holligan
Alena Holligan
Treehouse Teacher

after

</form>

add the following line:

<?php } ?>

You might also have an exit in the initial if statement. It seems to me that your code will stop if you have posted information.

Another thing, typos in main.twig, contact.twig can also cause these problems. Look at the nav link in your main.twig to make sure that is correct as well.