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 trialStephen Danforth
7,982 PointsData.php seems to have broken the site.
Hello, I don't know if I screwed up or there's a bug in the system. It seems that when I link anything to data.php, the site displays nothing. It's just white, there's no header or footer, just a white space. I looked over the video and the code on the lessons and I'm pretty sure I got everything right. Here's the coding for catalog.php and (some) data.php. I, admittedly moved on with the lessons (I have a time limit with this account, sorry!), so there's some stuff not on this lesson.
Catalog.php:
<?php
include("inc/data.php");
include("inc/function.php");
$pageTitle = "Full Catalog";
$section = null;
if (isset($_GET["cat"])) {
if ($_GET["cat"] == "books") {
$pageTitle = "Books";
$section = "books";
} else if ($_GET["cat"] == "movies") {
$pageTitle = "Movies";
$section = "movies";
} else if ($_GET["cat"] == "music") {
$pageTitle = "Music";
$section = "music";
}
}
include("inc/header.php"); ?>
<div class="section catalog page">
<div class="wrapper">
<h1><?php echo $pageTitle ?></h1>
<ul class="items" >
<?php
foreach($catalog as $id => $item) {
echo get_item_html($id,$item);
}
?>
</ul>
</div>
</div>
<?php include("inc/footer.php"); ?>
Data.php:
<?php
$catalog = [];
$catalog[101] = [
"title" => "Design Patterns",
"img" => "img/media/design_patterns.jpg",
"genre" => "Tech",
"format" => "Paperback",
"year" => 1994,
"catagory" => "Books",
"isbn" => "978*0201633610",
"publisher" => "Prentice Hall",
"authors" => [
"Erich Gamma"
"Richard Helm"
"Ralph Johnson"
"John Vlissides"
]
];
$catalog[102] = [
"title" => "Clean Code: A Handbook of Agile Software Craftsmanship",
"img" => "img/media/clean_code.jpg",
"genre" => "Tech",
"format" => "Ebook",
"year" => 2008,
"category" => "Books",
"authors" => [
"Robert C. Martin"
],
"publisher" => "Prentice Hall",
"isbn" => '978-0132350884'
];
Yadda yadda
Am I missing something painfully obvious here? Is there a bug I don't know about? I'm on Firefox if that helps.
Here's a snapshot of the code:
Stephen Danforth
7,982 PointsI added a snapshot if it helps.
3 Answers
Mike Costa
Courses Plus Student 26,362 PointsI checked out your snapshot and looked at data.php.
Add commas to your authors array in $catalog[101]
$catalog[101] = [
"title" => "Design Patterns",
"img" => "img/media/design_patterns.jpg",
"genre" => "Tech",
"format" => "Paperback",
"year" => 1994,
"catagory" => "Books",
"isbn" => "978*0201633610",
"publisher" => "Prentice Hall",
"authors" => [
"Erich Gamma"
"Richard Helm"
"Ralph Johnson"
"John Vlissides"
]
];
Stephen Danforth
7,982 PointsIt worked, thank you! I can't believe I missed that.
Mike Costa
Courses Plus Student 26,362 PointsNo problem Stephen Danforth, happy to hear it worked! :)
Pepe Suarez
18,267 PointsHey Stephen! Check your include("function.php"), in the course the file is saved as "functions.php" and you might forgot the "s" . Your code looks well if that is not the problem it might be in your functions.php file. Maybe can you attach it to check if the problem is in that file.
Stephen Danforth
7,982 PointsI tried changing the names of the files and it still didn't work.
Pepe Suarez
18,267 PointsCan you attach the function.php file ? Maybe the error is in there
Mike Costa
Courses Plus Student 26,362 PointsLooks like you forgot a semicolon at the end of this echo.
<h1><?php echo $pageTitle ?></h1>
Stephen Danforth
7,982 PointsI added it but it had no effect, thanks though!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsAre you doing this in workspaces?
If so you can post a snapshot of your workspace.