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

What isset() function exactly do in PHP? Is it really necessary to use in the "Build a Basic PHP Website" project?

Hi everyone,

I'm currently doing the "Build a Basic PHP Website" course and I'm seeing Alena use the isset function, she says that we need to use it to do another check? Why do we need to do another check? I'm trying out the code without the isset() function and it still works fine the way it is, what's the difference?

1). What is it exactly used for?

2). Do you have to use it?

3). When is it good practice to use it?

Thanks!

2 Answers

suyash patankar
suyash patankar
2,310 Points

Hello yes it is necessary to make another check, because if you see carefully you will find that in header.php we are passing category through URL using <a href="">

<ul class="nav"> <li class="books"><a href="catalog.php?cat=books">Books</a></li> <li class="movies"><a href="catalog.php?cat=movies">Movies</a></li> <li class="music"><a href="catalog.php?cat=music">Music</a></li> <li class="suggest"><a href="suggest.php">Suggest</a></li> </ul>

BUT WHAT IF A PAGE DOES NOT HAVE CATEGORY SET IN <a href="">??? IN THAT CASE OUR if-else STATEMENTS IN catalog.php WILL NEVER BE EXECUTED AND WE WILL GET UNDEFINED INDEX ERROR, to demo this please comment isset function and run http://port-80-ncrrxw2vyd.treehouse-app.com/catalog.php

It is necessary to use it to avoid any undefined index error

Hi suyash patankar, unfortunately you can't link to files in one of your Workspaces directly. Instead, you would need to share a Snapshot of your workspace, and Ken Chung would need to 'Fork' it to use/test that code.

suyash patankar
suyash patankar
2,310 Points

Hi @Iain Simmons I will try that way, thank you very much for the help.