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 trialIslamike Momen
Courses Plus Student 7,621 PointsHow 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="">— Select —</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
17,781 Pointshtml
<form method="post" action="process.php">
Yaswanth Goli
6,872 Pointsif 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]'";
Islamike Momen
Courses Plus Student 7,621 PointsI 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
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".
Islamike Momen
Courses Plus Student 7,621 PointsThank for the reply but it doesn't work.
Chris Dziewa
17,781 PointsTry 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
17,781 PointsP.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.
Islamike Momen
Courses Plus Student 7,621 PointsSorry, but which opening tag do you mean?
Chris Dziewa
17,781 PointsThe first of the form tags: <form method="post" action="process.php">
Islamike Momen
Courses Plus Student 7,621 PointsI 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
17,781 PointsDid you try removing any whitespace?
Chris Dziewa
17,781 PointsAlso What is that closing p tag doing next to the select?
Islamike Momen
Courses Plus Student 7,621 PointsIslamike Momen
Courses Plus Student 7,621 PointsThanks Christopher. Finally I passed it :)
Chris Dziewa
17,781 PointsChris Dziewa
17,781 PointsAwesome! Glad it worked for you!