PHP Build a Basic PHP Website (2018) Adding a Basic Form HTML Forms

MacKenzie T. Stout
MacKenzie T. Stout
23,972 Points

How do I change an ID attribute within a <select> tag in a $_POST array?

I added a $_POST array containing "flavor" to the <select> tag but am getting a "Bummer" on my challenge because "The <select> tag needs its 'name' attribute set to 'flavor'.

index.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 id=$_POST["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>

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,342 Points

Hi Mackenzie. You need to use the "name" attribute on the select html tag.

        <select id="flavor" name="flavor">

That way the data will be send to the php script. Good luck :)

<!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>
MacKenzie T. Stout
MacKenzie T. Stout
23,972 Points

Thank you, I couldn't figure out what I was missing!