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) Listing and Sorting Inventory Items Associative Arrays

Ted Gransbury
Ted Gransbury
Courses Plus Student 1,381 Points

Notice/Warning in preview after pasting text file in to data.php -- Found solution.

By the end of this video, after pasting the contents of the text document from Teacher's Notes as directed, my preview page is broken.

At 4:51 Alena highlights ALL code between the opening and closing php tags and presumably erases/replaces all of it with what's in the text file. The next time we see the top of the code, at 5:29, we see on line 2 "$catalog = [];" and on line 3 "//Books" ... while I understand "//Books" is commented out and doesn't make any difference, the "$catalog = [];" makes a world of difference, especially since it is NOT in the text document we've been directed to therefore it does NOT get added to the data.php file (which prior to pasting the text document had the "$catalog = [];" line but now doesn't since we erased/replaced everything between the opening and closing php tags) leading to the following errors being displayed in the preview:

"Notice: Undefined variable: catalog in /home/treehouse/workspace/catalog.php on line 33"

"Warning: Invalid argument supplied for foreach() in /home/treehouse/workspace/catalog.php on line 33".

Being a newbie I first checked my data.php code line 33 since that's the last file I modified... it doesn't contain "foreach"... however catalog.php line 33 does (as the errors indicate). So by omitting the "$catalog = [];" line from the top of the data.php file, everything is left undefined and broken. Add that line back in and BOOM. Things work.

The error confused me far longer than it should have.