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

How to access "flavor" in $_POST["flavor] from the form element?

I'm stock in this code challenge. I can't seem to find a solution.

Here is the question: "Next, we need the flavor selected in the dropdown to be submitted to this process.php file. We need to be able to access it in the β€œflavor” element of the $_POST array like this: $_POST["flavor"]. What two changes do we need to make to the HTML? (Hint. We need to add two new attributes. The first needs to be added to one existing HTML element, the second needs to be added to a different existing HTML element.)" Here is the pre-set HTML/PHP :

<!DOCTYPE html>
<html>
<head>
    <title>Ye Olde Ice Cream Shoppe</title>
</head>
<body>

    <p>Your order has been created. What flavor of ice cream would you like to add to it?</p>

    <form method="POST" action="process.php">

        <label for="flavor">Flavor</label>
        <select name="flavor" id="flavor">
            <option value="">&#8212; Select &#8212;</option>
            <option value="Vanilla">Vanilla</option>
            <option value="Chocolate">Chocolate</option>
            <option value="Strawberry">Strawberry</option>
            <option value="Cookie Dough">Cookie Dough</option>
        </select>

        <input type="submit" value="Update Order">

    </form>

</body>
</html>

Thanks for any enlightenment in this topic.

4 Answers

Chris Dziewa
Chris Dziewa
17,781 Points
html
<form method="post" action="process.php">

Thanks Christopher. Finally I passed it :)

Chris Dziewa
Chris Dziewa
17,781 Points

Awesome! Glad it worked for you!

Yaswanth Goli
Yaswanth Goli
6,872 Points

if you are accessing like a variable use: $_POST["flavor"] if you are using in a query statement like $sql="select * from table where item ='$_POST[flavor]'";

I guess I have to upload link to the video that associated with this code challenge. Here is the link. The code challenge follows after this video.

Still need help with it. Thanks for the reply.

Aina M
Aina M
3,470 Points
<form method="post" action="process.php">

With "post" in lower case, does it work ? I think it should be case insensitive, but in the code challenge, it doesn't work with "POST" and it works with "post".

Thank for the reply but it doesn't work.

Chris Dziewa
Chris Dziewa
17,781 Points

Try this again with the "post" for method in lowercase. Also, this may be a picky grader so for the select tag, try putting name="flavor" at the end of the opening tag.

Chris Dziewa
Chris Dziewa
17,781 Points

P.S. I tried your code with the method="POST" and it fails because of the uppercase. Upon changing this, it worked fine. Make sure to always use method="post" in the opening form tag.

Sorry, but which opening tag do you mean?

Chris Dziewa
Chris Dziewa
17,781 Points

The first of the form tags: <form method="post" action="process.php">

I did try lowercase 'post' as suggested but I still can't pass :(

Here is the code I modified to pass

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

        <label for="flavor">Flavor</label>
        <select name="flavor" id="flavor"></p>
            ```
Chris Dziewa
Chris Dziewa
17,781 Points

Did you try removing any whitespace?

Chris Dziewa
Chris Dziewa
17,781 Points

Also What is that closing p tag doing next to the select?