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 trialAntwaun Johnson
Courses Plus Student 11,157 Pointsdetails page is redirecting to catalog.php
<?php
include("inc/data.php");
include("inc/functions.php");
if (isset($_GET["id"])) {
$id = $_Get["id"];
if (isset($catalog[$id])); {
$item = $catalog[$id];
}
}
if (!isset($item)) {
header("location:catalog.php");
exit;
}
$pageTitle = $item["title"];
$section = null;
include("inc/header.php"); ?>
<div class="section page">
<div class="wrapper">
<div class="media-picture">
<span>
<img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>" />
</span>
</div>
<div class="media-details">
<h1><?php echo $item["title"]; ?></h1>
<table>
<tr>
<th>Category</th>
<td><?php echo $item["catagory"]; ?></td>
</tr>
<tr>
<th>Genre</th>
<td><?php echo $item["genre"]; ?></td>
</tr>
<tr>
<th>Format</th>
<td><?php echo $item["format"]; ?></td>
</tr>
<tr>
<th>Year</th>
<td><?php echo $item["year"]; ?></td>
</tr>
<?php if (strtolower($item["category"]) == "books") { ?>
<tr>
<th>Authors</th>
<td><?php echo implode(", ",$item["authors"]); ?></td>
</tr>
<tr>
<th>Publisher</th>
<td><?php echo $item["publisher"]; ?></td>
</tr>
<tr>
<th>ISBN</th>
<td><?php echo $item["isbn"]; ?></td>
</tr>
<?php} else if (strtolower($item["catagory"]) == "movies") { ?>
<tr>
<th>Director</th>
<td><?php echo $item["director"]; ?></td>
</tr>
<tr>
<th>Writers</th>
<td><?php echo implode(", ",$item["writers"]); ?></td>
</tr>
<tr>
<th>Stars</th>
<td><?php echo implode(", ",$item["stars"]); ?></td>
</tr>
<?php} else if (strtolower($item["catagory"]) == "music") { ?>
<tr>
<th>Artist</th>
<td><?php echo $item["artist"]; ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div> ```
I have copied everything from each video regarding the details page. If someone could point to something that I may be overlooking, that would be great.
1 Answer
Antonio De Rose
20,885 Pointswell and truly, this will redirect to catalog.php, given your code, had the $item is not set
<?php
include("inc/data.php");
include("inc/functions.php");
if (isset($_GET["id"])) {
$id = $_Get["id"];
if (isset($catalog[$id])); {
$item = $catalog[$id];
}
}
//use a var_dump here to see what is actually the $item is returning
//if it is not returning anything, as per to your code it will have to go to catalog.php
var_dump($item)
if (!isset($item)) {
header("location:catalog.php");
exit;
}
Antwaun Johnson
Courses Plus Student 11,157 PointsAntwaun Johnson
Courses Plus Student 11,157 PointsThanks Antonio, I finally resolved this issue, working on a new one now. I appreciate your help