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 trialJose Reyna
13,532 PointsMy code is broken somewhere and I can't find the error.
Hello!
I have run through the video multiple times checking for syntax and also downloaded the project files, which didn't help, however, my code is still not working and I can't seem to figure out why not.
Here is a snapshot https://w.trhou.se/mbcnhgkcnj
5 Answers
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsHi Jose,
You have a typo/misspelling on line 6 of catalog.php:
$secont = null;
It should be:
$section = null;
Jason Anello
Courses Plus Student 94,610 Pointschanged from comment to answer
Also, you were missing a right parenthesis on line 12 of functions.php
It should be
if ($category == null) {
Jose Reyna
13,532 PointsThank you, Juliette, completely missed that. I fixed the error and the one Jason mentioned but still no luck, yet.
Jason Anello
Courses Plus Student 94,610 PointsI had forked your workspace and fixed those 2 errors and everything seemed to be working correctly for me.
Are you seeing a blank white page or something else?
You can post a new snapshot if you need to.
Jose Reyna
13,532 PointsThank you both! I appreciate your help! I finally found it! Jason, it was the missing parenthesis on line 12 in functions.php.
You two rock! Thank you again.
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsAwesome.
BTW, I just remembered that I came across this cool PHP code checker yesterday. Maybe it can help us all in the future. I know that sometimes looking for an error or syntax typo can sometimes be like looking for a needle in a haystack:-)
Jason Anello
Courses Plus Student 94,610 PointsGlad you got it working.
It might be good experience for you to try the htaccess file and take the parenthesis back out so you can see what the message looks like and see if it makes sense.
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsTry removing the "." in the href path on line 11 of header.php.
You have this:
<a href="./">
Try this:
<a href="/">
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points..also, you have a space in your path on line 14 of header.php:
a href="catalog.php? cat=books">
It should be:
<a href="catalog.php?cat=books">
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsThe other thing that I noticed (and I forget why this is necessary & to be honest, I'm going to have to watch the video again myself) is that you do not have a space in between " and "on" on lines 14, 15, 16, & 17:
{ echo "on";}
It should be:
{ echo " on"; }
I hope that this helps:-)
Jose Reyna
13,532 PointsThanks again Juliette! I'll try those changes.
Jason Anello
Courses Plus Student 94,610 PointsThat part is ok because there's a space before the opening php tags.
<li class="books <?php if ($section == "books"){ echo "on";} ?>">
As long as you put the space after books
or before on
it will work the same way.
It's preferable to do it the way you have shown so that you don't have a trailing space in the class name if the on class isn't echoed. This doesn't cause any problems though.
The reason for the space is so that the result will be "books on" instead of "bookson" which would cause the css not to work correctly.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThe php environment within workspaces currently has
display_errors
turned off. This makes it hard to find these kinds of syntax errors.The staff is currently looking into this and will hopefully get it turned back on.
In the meantime, you can create a .htaccess file in workspaces to turn the errors back on.
Warning! You should only do this for development and not on a live production site.
Create a new file named "htaccess.txt" This is only so you can edit and preview the file. It's not the correct file name.
Add the following:
php_flag display_errors 1
After saving the file, rename it to ".htaccess" That's a dot and then htaccess
Now, instead of getting a blank white page on syntax errors you'll be told the file and line number where the parse error occurs. This should make it easier to fix.