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 trialPrakhar Patwa
11,260 Pointshaving trouble to understand the concept of product_id = $_GET["id"];
In the shirt.php we have declared $product_id = $_GET["id"]; i am not getting $_GET["id"] , where we have define the variable "id",we define only $product_id in order to get the key Please help me to clear that doubt.
3 Answers
Shawn Gregory
Courses Plus Student 40,672 PointsPrakhar,
To expand on what Guan is stating: When you send any information from a form, there are two methods of doing so: post and get. POST sends all the information obtained in the form in the headers of the page while all information sent using GET is sent via the URL. If you remember from looking at the search page, when you did the form, you set the METHOD to get. When you are dealing with the form data on the target page, if you want to access the data if you set the form method to post, you would use $_POST. At the same time, if you use the METHOD get, you would use $_GET as specified in the video.
METHOD: GET
How It's Set
<form action="search.php" method="get">
<input type="text" id="query" name="q">
</form>
How It's Transferred
http://www.website.com/search.php?q=red
How It's Accessed
<?php
$_GET['q'];
?>
METHOD: POST
How It's Set
<form action="search.php" method="post">
<input type="text" id="query" name="q">
</form>
How It's Transferred
http://www.website.com/search.php (Remember it's sent via page headers and not from the URL)
How It's Accessed
<?php
$_POST['q'];
?>
You would use POST if you are sending sensitive information or a lot of information from a form. You would use GET if you are sending just a few pieces of information. I hope this helps you better understand the difference.
Cheers!
Diren Yardimli
6,494 Points"id" is defined in the url.
Aaron Munoz
11,177 PointsThere's a workshop on Get and Post methods in the development tools category. That should help you understand the fundamentals.
Ted Sumner
Courses Plus Student 17,967 PointsI don't see the workshop. Will you post a link? I would love to refresh myself by watching it.
Aaron Munoz
11,177 PointsSorry, it's actually in the digital literacy section. GET workshop
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsVery clear explanation. I only want to add that many programmers use post almost exclusively because it keeps the URL clean and is much more secure.
Aaron Munoz
11,177 PointsAaron Munoz
11,177 PointsPost is to send data, which is why it's secure. Get is to retrieve data. Example:
You use a Get to retrieve a keyword search.
You use a post to send an email.
Prakhar Patwa
11,260 PointsPrakhar Patwa
11,260 Pointsthankx shawan gregory. its really helpful.
Kenn Hyatt
9,683 PointsKenn Hyatt
9,683 PointsBy far the best explanation I have ever heard for anything!
Good Form!