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

alex mattingley
alex mattingley
7,508 Points

Contact.php not redirecting properly

Hey all,

On the last video/last step of contact form tutorials, but cant seem to get my contact form to direct properly. If I am at my localhost/contact.php page and I input data and hit submit, its redirecting to localhost/contact.php and just giving me a blank page.

I think it's supposed to display http://localhost/contact.php?status=thanks as the URL but for some reason it is not directing there. However if I type that address straight into the search bar, it loads the thanks page easily.

Here is the entirety of my code from contact.php


    $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 Email

    header("Location: contact.php?status=thanks");
$titlepage = "Contact Mike";
$section = "contact"; 
include ('inc/header.php');

<div class="section page">

    <div class= "wrapper">


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

        <p style= "text-align:center;">Thanks! We will contact you shortly!</p>

    <?php } else { ?>

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

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

            (** I left out the table code to conserve space**)  
            <input type="submit" value="send">
    <?php } ?>



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

Any help would be greatly appreciated.

1 Answer

alex mattingley
alex mattingley
7,508 Points

Ok so for some reason it started working and I have no idea why. I would still appreciate it if someone would take a look at the code and let me know if there are any bugs.