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

Get variables, can't get it right

I've been staring at my code for too long.

I'm getting a Not found error:

"The requested URL /contact-process.php was not found on this server."

I've deleted contact-process.php and I think I don't have any link to it on my code.

Please help!

My contact.php

<?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 . "\n";

// TODO: Send Email

header("Location: contact.php?status=thanks!");
exit;
}
?>

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



    <div class="section page">

       <div class="wrapper">

        <h1>Contact</h1>

           <?php if (isset($_GET["status"]) and $_GET["staus"] == "thanks") { ?>
              <p>Thanks for the email! I&rsquo;ll be in touch 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">

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

                     <td>
                        <input type="text" name="email" id="name">
                    </td>
                    </th>    
                </tr>
                 <tr>
                    <th>
                        <label for="message">Message</label>

                     <td>
                        <textarea type="text" name="message" id="message"></textarea>
                    </td>
                    </th>    
                </tr>
            </table>

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

        <?php } ?>

        </div><!--end wrapper-->
    </div>

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

4 Answers

Hi tuukka,

I'm not sure about your error related to contact-process.php but you have an exclamation mark at the end of your query string.

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

This will cause the $_GET part of your code not to work.

For the contact-process error, I don't see any reference to that either in your code.

Double check that your url is "...contact.php" when you're filling out the form and then see if it changes to "...contact.php?status=thanks" after submitting.

Is it possible you were using an older version of the page in the browser and the form action was still "contact-process.php"?

Thanks Jason,

I'll try these when I get back home.

I did refresh the browser if that's what you mean.

I'll get back to this thread later.

Thanks!

Alright.

If you're still having a problem then let us know what the url is when you're filling out the form and then what do you see on the page and what's the url after you have submitted the form.

I had a typo in there :)

and $_GET["staus"] == "thanks") { ?>

It should have bee status but I misspelled it staus.

Thanks for your help anyways!

Different issue, wondering why you didn't cite your php includes folder before the "header.php" address, like so:

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