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 trialJames Mockridge
4,043 PointsBlank page on details.php
Not sure where I went wrong. I would be grateful for any pointers.
<?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;
}
$page_title = $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>
James Mockridge
4,043 PointsHello Romuald,
I did enter the category id (id =101) into the address bar and it came up as blank white page. Without the id I get a redirect to catalog.php.
I will try out your code and see if it is a problem on details.php. If I can rule that out I can be sure the problem is coming from one of the include files.
Thank you for responding and for your code.
Edit: Your code worked which means that the problem is on my version of details.php rather than one of the include file.
3 Answers
Matthew Bilz
15,829 PointsIn this part of your code:
if(isset($_GET["id"])) {
$id = $_GET("id");
Try putting the $id = $_GET("id"); into square brackets - $id = $_GET["id"];
Should work!
Romuald Le Bris
3,975 PointsThat's it Matthew ! That was the mistake between his code and mine. :)
James Mockridge
4,043 PointsOh bugger you beat me to it
Matthew Bilz
15,829 PointsHa!!!
I guarantee you 90% of any issues will be forgetting the $ before a variable, forgetting a semi-colon or mixing up brackets. Fun stuff, right? :)
Laura Cecil
Courses Plus Student 17,903 PointsThank you!
Romuald Le Bris
3,975 PointsCool ! I'm glad my answer helped you man :) Yeah maybe you missed a semi colon or a curly brace... Anyway great news if it works now ;)
Make sure to up-vote the answer for people who might have in the future the same problem as yours ;)
James Mockridge
4,043 Pointsafter a side by side comparison I found the issue. I used brackets () rather than square brackets [].
this
$id = $_GET("id");
should be
$id = $_GET["id"];
The issue is resolved. Check your brackets everyone.
Romuald Le Bris
3,975 PointsBy the way if you copied my code in yours James, be careful with your variable $page_title as mine is called $pageTitle. So you might want to change it to your variable for your global code environment to work properly :)
Romuald Le Bris
3,975 PointsRomuald Le Bris
3,975 PointsHi James, your code seems to be good. What happen in your browser when type in the URL : http://port-80-txcdzassgc.treehouse-app.com/details.php?id=102
Does it shows you the img and the title of the $item correctly ?
Also, if you type in the URL : http://port-80-txcdzassgc.treehouse-app.com/details.php
As there is no "id" found thanks to the variable $_GET in the URL, your code should automatically redirect to the catalog.php page. If it doesn't, then you have a problem of redirection.
Here is my code that works fine for details.php :
Hope it will help you ! Have a great day !