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 Basic PHP Website (2018) Building a Media Library in PHP Working with _GET Variables

Teacher Russell
Teacher Russell
16,873 Points

working with GET variable

I'm confused about the explanation at the beginning as to why we're using the GET variable this way. ..."to check which category should be displayed"? I don't get what it is we're trying to do here. I understand what GET does when I've seen it used in forms.

1 Answer

Shayne Laufenberg
Shayne Laufenberg
4,213 Points

In PHP we use $_POST and $_GET and each of them are used for different reasons. Generally we use $_GET as a way to allow someone to request a specific set of data from our website. For example on teamtreehouse when you visit your profile or another users profile you are using a $_GET variable. That $_GET variable is then sent to the server at your request and a message is sent back. Typically in a dynamic php website we will use this $_GET variable as a condition when dealing with databases which will then allow us to retrieve content. You generally do not want to use $_GET variables in forms although you could its much more practical to use $_GET when retrieving information and $_POST when pushing (Insert, Update, Deletion) using a database or in simple cases for posting data to another page. For example...

teamtreehouse.com/shaynelaufenberg

would be similar to something like

teamtreehouse.com/example.php?user=shaynelaufenberg

then it can be rewritten in apache .htaccess to look better.

This makes more sense once you start dealing with higher level PHP and working with complex database systems but for now just know that $_GET is for users requesting information, and $_POST is for forms like a Login or Registration page. Hopefully this helps and if you have any other questions about the subject just let me know :)

Teacher Russell
Teacher Russell
16,873 Points

I think I get all that, and suspected that's what this was about, but her explanation confused me. I still don't get what she's saying. She's basically pretending to be a user typing the specific folder into the browser? The whole cat thing is messing with me. Seemed like she was creating a variable in the browser:) Thanks a lot!