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

Not able to access catalogue page

I am working through this using the MAMP server service and using Atom text editor. When I try to access the Music, movies, or books pages, I receive a 404 error telling me that /catalogue.php isn't found.

I've looked in the file path for MAMP to make sure that catalogue.php is saved correctly, and the index and suggest pages load correctly.

I checked the logs for MAMP and I see the following errors:

[24/Nov/2020:17:52:38 -0500] "GET /catalog.php?cat=music HTTP/1.1" 404 209 [24/Nov/2020:17:53:48 -0500] "GET /catalog.php?cat=music HTTP/1.1" 404 209

So far this is my code for the catalogue page:

 <?php
$pageTitle = "Full Catalogue";

if (isset($_GET["cat"])) {
  if ($_GET["cat"] == "books") {
    $pageTitle = "Books";
  } else if ($_GET["cat"] == "movies") {
    $pageTitle = "Movies";
  } else if ($_GET["cat"] == "music") {
    $pageTitle = "Music";
}

 include('inc/header'); ?> 
<div class="section page">
    <h1>Full Catalog</h1>
</div> 
<?php include("inc/footer"); ?>

I hope that this formats correctly.

3 Answers

So, with some help from a fiend (who did not see it immediately either) we finally figured out that I was missing a closing bracket at the end of the if statement.

To anyone else who decides to use MAMP to host the local server, it is worth enabling error messages in order to help identify syntax errors.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

You got the markdown formatting right, well done. :)

Try renaming your catalog file from catalogue.php to catalog.php. There definitely seems to be a name disparity. The code wants you to use catalog.php to correctly link it to the main catalog page.

Hi Jonathan,

Thanks for the head's up on the catalog name issue. I definitely overlooked this.

I've made this edit, however I am seeing a 500 error when trying to access this now.

Checking the error logs in MAMP, I am now seeing the following:

25-Nov-2020 19:00:45 UTC] PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in \AppData\Roaming\Appsolute\MAMP\pscripts\file-f7e3809a-4f83-4368-9f44-86cbdd97f7f2.php on line 3 [25-Nov-2020 19:00:45 UTC] PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in \AppData\Roaming\Appsolute\MAMP\pscripts\file-f7e3809a-4f83-4368-9f44-86cbdd97f7f2.php on line 12 [25-Nov-2020 19:00:45 UTC] PHP Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in \AppData\Roaming\Appsolute\MAMP\pscripts\file-f7e3809a-4f83-4368-9f44-86cbdd97f7f2.php on line 13 [25-Nov-2020 19:00:45 UTC] PHP Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in \AppData\Roaming\Appsolute\MAMP\pscripts\file-f7e3809a-4f83-4368-9f44-86cbdd97f7f2.php on line 16 [25-Nov-2020 19:00:45 UTC] PHP Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in \AppData\Roaming\Appsolute\MAMP\pscripts\file-f7e3809a-4f83-4368-9f44-86cbdd97f7f2.php on line 21 [25-Nov-2020 19:00:47 UTC] PHP Parse error: syntax error, unexpected end of file in C:\server\catalog.php on line 21 [25-Nov-2020 19:01:01 UTC] PHP Parse error: syntax error, unexpected end of file in C:\server\catalog.php on line 21

Perhaps I am still overthinking this?

Kind Regards,

Mark

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Without looking at the code I can only think from the Syntax errors there's there's a misplaced semicolon or other syntax error that's causing PHP to think it's come to the end of the file too early. Have a look for that and things like mismatched parentheses. Then the page should be recognised by PHP. 😊