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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ker Sing Tan](https://secure.gravatar.com/avatar/87b225b41176bb34e1a27e197d77c7d3?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ker Sing Tan
10,573 PointsWhy isset ?
I am not quite understand why isset() will make the undefine error gone? Since we have set the if statement for all 3 catalogs $_GET["cat"], why have to use isset() ?
2 Answers
![Ryan Groom](https://secure.gravatar.com/avatar/b8efae51bc92cad353f2e631a821308e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ryan Groom
18,674 PointsHello Ker Sing Tan , In this video, the "if" statement is not actually setting the variable of cat. The if statement is only checking to see if the "cat" variable is set to a specific string such as "books" or "music" or "movies". When the instructor adds ?cat="music" to the URL, this is what is setting the variable of "cat". So when she removes this from the URL in the video, "cat" is undefined because the variable is not being set to anything. When she adds the isset() function to $_GET["cat"] in the code, it is causing the code to perform the "if" and "else if" statements ONLY if the cat variable is set... so therefore if the variable is NOT set in the URL, then the "if" and "else if" statements never execute and therefore no error is produced. I hope this helps, if not, you are welcome to reply back and tell me what you're having trouble understanding.
![Jon Guest](https://uploads.teamtreehouse.com/production/profile-photos/11710044/micro_Storm.jpg)
Jon Guest
1,532 PointsVery good answer.
KEY TAKEAWAYS
"When the instructor adds ?cat="music" to the HTML , this is what is setting the variable of "cat"."
( <a href="catalog.php?cat=music"> an unusual place to name a variable )
Really good BRAIN TWISTER for beginners: Here we need to decide. Should we let a program run our code block if it produces an error. We decide to let it run only if the conditions are met.
if ( isset ($_GET["cat"])) {
- write code you want to run
- if () checks with isset() if $_GET[] has variable ?cat created }
Ker Sing Tan
10,573 PointsKer Sing Tan
10,573 PointsThank you for detail explanation.
Geraldo Hernandez
7,515 PointsGeraldo Hernandez
7,515 PointsGreat explanation, thank you.