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 Integrating with PayPal HTML Forms

Darren Joy
Darren Joy
19,573 Points

PHP simple app challenge for posting flavor info

From the Build a simple php application course

challenge 2 of 3

"Challenge Task 2 of 3

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.)"

In challenge part 1 we add : action="process.php" to the <form>

and in this one we add method="POST"

to get:

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

And then it wants you to use the $_POST array for the selected flavor but I can't for the life of me figure out how to do it.

I want to make this equal something, the selected flavour but can't seem to figure out the right syntax for it...

I know this line is wrong:

<select = <?php $_POST["flavor"] ?> id="flavor">

But can't punch my way out a bag of confusion on this one.

original line was:

<select id="flavor">
form.html
<!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 action="process.php" method="POST">

        <label for="flavor">Flavor</label>
        <select = <?php $_POST["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>
Darren Joy
Darren Joy
19,573 Points

Bummer warning:

Bummer! It looks like you have added an attribute to the select element, but it's not the attribute that determines how to access the value on the server.

2 Answers

Michelle Hurwitz
Michelle Hurwitz
11,854 Points

You only need to add name="flavor attribute to the select tag, as follows -

<!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 action="process.php" method="post">

    <label for="flavor">Flavor</label>
    <select id="flavor" name="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>

Darren Joy
Darren Joy
19,573 Points

Ah HA! Thank you!

It's way too late for me to be trying to code this stuff lol!

Darren Joy
Darren Joy
19,573 Points

Getting this error now:

Bummer! It looks like you have added the right attribute (method) to the right element (the form), but it has the wrong value. Hint: we need to set the request method so that values are accessible in the $_POST array.

time to rest my weary head for then night

Darren Joy
Darren Joy
19,573 Points

It was a one two punch... apparently it didn't like me calling the method as POST with capital letters..

as well as the missing name="flavor"