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

Alexander Rasmussen
Alexander Rasmussen
12,901 Points

This webpage has a redirect loop ??

Hello I am getting this error message and i don't know what i have done wrong. Is there anyone who can see the error?

<?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 . "Besked: " . $message;
    header("Location: contact.php?status=thanks");
    exit;
?>


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

    <div class="EmailForm">

        <h1>Kontakt</h1>

        <?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
            <p>Tak for din henvendelse! Vi svarer hurtigst muligt!</p>
        <?php } else { ?>

        <p>Vi vil elske at høre fra dig! Send os en besked her!</p>

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

            <table>
                <tr>
                    <th>
                        <label for="navn">Navn</label>
                    </th>
                    <td>
                        <input type="text" name="name" id="navn">
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="email">E-mail</label>
                    </th>
                    <td>
                        <input type="text" name="email" id="email">
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="message">Besked</label>
                    </th>
                    <td>
                        <textarea type="text" name="message" id="message"></textarea>
                    </td>
                </tr>
            </table>
            <input type="submit" value="Send">
        </form>
        <?php } ?>
    </div>

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

2 Answers

Hi Alexander,

What error message are you getting?

You have your closing brace at the end of this line: if ($_SERVER ["REQUEST_METHOD"] == "POST") {} instead of after the exit; statement.

Alexander Rasmussen
Alexander Rasmussen
12,901 Points

Thank you very much ! That was the issue that was causing the problem ! :)