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 trialcalvindiguidig
Courses Plus Student 4,388 PointsNotice: Undefined index: director in /home/treehouse/workspace/details.php on line 69
hi guys can you explain to me why i get this error i'm trying to follow alone the tutorial i'm stuck in this error the code should be look for an array ["director"] but it seems doesn't find the array
calvindiguidig
Courses Plus Student 4,388 Points<?php
include("inc/data.php");
include("inc/function.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["category"];?></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><!--use implode method to seperate authors in commas -->
</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["category"])=="movies") { ?>
<tr>
<th>Director</th>
<td><?php echo $item["director"];?></td>
</tr>
<?php }?>
</table>
</div>
</div>
</div>
calvindiguidig
Courses Plus Student 4,388 Points<?php} else if(strtolower($item["category"])=="movies") { ?>
<tr>
<th>Director</th>
<td><?php echo $item["director"];?></td>
</tr>
<?php }?>
this code should be look for movies category but it showing an error
3 Answers
Torger Angeltveit
11,228 PointsI think you need to use single qouts in this line
<img src ="<?php echo $item['img'];?>" alt ="<?php echo $item['title'];?>" />
calvindiguidig
Courses Plus Student 4,388 PointsThanks for help but the problem is when I try to use else if statement to look for an array it's it's gives me error
Michael Simmons
9,149 PointsI ran into this same problem and I finally figured it out. Add space between php and the closing curly bracket.
This
<?php} else if(strtolower($item["category"])=="movies") { ?>
Should look like this
<?php } else if(strtolower($item["category"])=="movies") { ?>
Joshua Paulson
37,085 PointsJoshua Paulson
37,085 PointsCould you provide a copy of the code you are working on so we could take a look?