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 Building the Shirt Details Page

Prakhar Patwa
Prakhar Patwa
11,260 Points

having 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

Prakhar,

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!

Very 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
Aaron Munoz
11,177 Points

Post 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
Prakhar Patwa
11,260 Points

thankx shawan gregory. its really helpful.

Kenn Hyatt
Kenn Hyatt
9,683 Points

By far the best explanation I have ever heard for anything!

Good Form!

"id" is defined in the url.

Aaron Munoz
Aaron Munoz
11,177 Points

There's a workshop on Get and Post methods in the development tools category. That should help you understand the fundamentals.

I don't see the workshop. Will you post a link? I would love to refresh myself by watching it.

Aaron Munoz
Aaron Munoz
11,177 Points

Sorry, it's actually in the digital literacy section. GET workshop