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 trialPepijn Dekker
Courses Plus Student 5,231 PointsImage will not load on the /details.php?id=102.
I think it's got to do with the <img src="<?php echo line. I followed Alena's direction and the alt tags load but the images on each id= page just wont show. Any ideas?
<?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>
</div>
Simon Coates
28,694 Points<?= is a shorthand PHP syntax to echo something to the screen. not recommended historically (not all environments supported it, I think). see http://stackoverflow.com/questions/2020445/what-does-mean-in-php
2 Answers
Lyle Lewton
Courses Plus Student 10,585 PointsHey! it looks like you just forgot an equals sign after "src" in your code.
change <img src"<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?> "/> to <img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?> "/>
I hope that helps :)
Dennis Amiel Domingo
17,813 PointsI too was having the same problem - the image for the item wasn't showing up. I had the exact same code. I checked my image source and the equals sign was already there.
What I did was change the double quotes for $item["img"] to single quotes (did the same for "title"), like so:
<img src="<?php echo $item['img'];?>" alt="<?php echo $item['title'];?>"/>
That solved it!
Pepijn Dekker
Courses Plus Student 5,231 PointsPepijn Dekker
Courses Plus Student 5,231 PointsSO I had.
<img src"<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?> "/>
Found someone had recommended this version.
<img src="<?= $item["img"]; ?>" alt="<?= $item["title"]; ?>" />
Why do we drop the php echo and move the = inside the < ?