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

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.