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

Modure Rares
PLUS
Modure Rares
Courses Plus Student 9,041 Points

Why the $status does not appear in the URL ?

Hello. I have a header PHP command that redirects the user to this "suggest.php?status=thanks" when a submit button is clicked. The problem is that when i click the submit button the URL of the page is this "http://localhost/testWebsite/suggest.php=thanks" and I get an notice "undefined index status". What am i doing wrong

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

        $name = $_POST["name"];
        $email = $_POST["email"];
        $details = $_POST["suggestion"];

        echo "<pre>";
        $email_body = "";
        $email_body .= "Name: " . $name . "\n";
        $email_body .= "Email: ". $email . "\n";
        $email_body .= "Details: " . $details ."\n"; #this represents a linebreak 
        echo $email_body;
        echo "</pre>";

        // EMAIL SENDING CODE HERE 

        //**********************************************

        header("location:suggest.php$status=thanks");
    }

    $pageTitle = "Suggest a Improvement";
    $section = "suggest";

    include("include/header.php");
 ?>


    <form id="suggestion" method="post" action="suggest.php">

        <h1 id="suggest-title">Suggest an Improvement</h1>

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

                echo "<div id='thanks'><h1> Thank You! </h1></div>";
            } else {?>
        <fieldset>

            <label for="name">Name:</label>
            <input id="name" type="text" name="name">

            <label for="email">Email:</label>
            <input type="email" name="email" id="email">

        </fieldset>

        <fieldset>

            <label for="suggestion">Suggest:</label>
            <textarea name="suggestion" id="user_ideea">your idea...</textarea>

        </fieldset>

        <fieldset>

            <input type="submit" value="Send">

        </fieldset>
    </form>
    <?php } ?>
 </body>
 </html>

1 Answer

Benjamin Larson
Benjamin Larson
34,055 Points

The dollar sign ($) should be changed to a question mark (?) in your query string.

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

Start with that and see if it fixes it.