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 trial
Matt Trask
10,027 PointsShirts.php wont show in localhost....again.
So, I was in the middle of adding the Paypal to my Mike the Frog project, and I was following Randy in the videos. But when I went to reload, my shirts.php page is blank. Ive rewatched the video and can not find my error. Can anyone take a look and see?
<?php include("inc/products.php"); ?><?php
$pageTitle = "Mike's Full Catalogue of Shirts";
$section = "shirts";
include('inc/header.php'); ?>
<div class="section shirts page">
<div class="wrapper">
<h1>Mike’s Full Catalogue of Shirts</h1>
<ul class="products">
<?php foreach($products as $product) {
echo "<li>";
echo '<a href="shirt.php">';
echo '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
echo "<p>View Details</p>";
echo "</a>";
echo "</li>";
}
?>
</ul>
</div>
</div>
<?php include('inc/footer.php'); ?>
10 Answers
Jacques Vincilione
17,292 PointsWhy are you including products.php in the products.php file?
Stefan Jansen
8,974 Pointsyou can get some insights on where the code breaks, if you have a look at the source code of the empty page. Not seeing something on screen, doesn't mean the source code is actually empty.
If the source code is also empty, than the issue will most likely be inside inc/products.php. What you could do is check if you wrote valid code. in a terminal just run php -l inc/products.php. This will lint (check) the code and does some basic validation of your code. Keep in mind this is not 100% foolproof solution for finding issues in your code.
If this still doesn't get you on your way, perhaps post the code of inc/products.php here.
Matt Trask
10,027 PointsHere is products.php. The source code was empty on shirts.php
<?php include("inc/products.php"); ?><?php
$products[101] = array(
"name" => "Logo Shirt, Red",
"img" => "img/shirts/shirt-101.jpg",
"price" => 18 ,
"paypal" => "U2Y7354QWZRME"
);
$products[102] = array(
"name" => "Mike the Frog Shirt, Black",
"img" => "img/shirts/shirt-102.jpg",
"price" => 20,
"paypal" => "7PQCPWAWBGLXJ"
);
$products[103] = array(
"name" => "Mike the Frog Shirt, Blue",
"img" => "img/shirts/shirt-103.jpg",
"price" => 20,
"paypal" =>
);
$products[104] = array(
"name" => "Logo Shirt, Green",
"img" => "img/shirts/shirt-104.jpg",
"price" => 18,
"paypal" =>
);
$products[105] = array(
"name" => "Mike the Frog Shirt, Yellow",
"img" => "img/shirts/shirt-105.jpg",
"price" => 25,
"paypal" =>
);
$products[106] = array(
"name" => "Logo Shirt, Gray",
"img" => "img/shirts/shirt-106.jpg",
"price" => 20,
"paypal" =>
);
$products[107] = array(
"name" => "Logo Shirt, Turquoise",
"img" => "img/shirts/shirt-107.jpg",
"price" => 20,
"paypal" =>
);
$products[108] = array(
"name" => "Logo Shirt, Orange",
"img" => "img/shirts/shirt-108.jpg",
"price" => 25,
"paypal" =>
);
?>
Paul Roberts
7,928 PointsCompletely unrelated, but looking through your question made me realise why my code wasn't working! So thanks a lot!
Matt Trask
10,027 PointsI guess that could be the issue. It should be shirts.php then instead of products.php
Jacques Vincilione
17,292 PointsNo, the products file is an include, it should not include the shirts.php file.
The shirts.php does need the products.php but not the other way around.
Stefan Jansen
8,974 Pointsif you include products into shirts, you don't need to include shirts into products.
the issue you have is caused by the parse error you are generating because of missing values in your products array.
entries for product 103 through 108 have noting after the paypal => parts of the array.
In php you will always need at least something, it can even be an empty string or a boolean.
example:
$products[108] = array(
"name" => "Logo Shirt, Orange",
"img" => "img/shirts/shirt-108.jpg",
"price" => 25,
"paypal" => ""
);
Matt Trask
10,027 Pointsyea Im adding the paypal id's right now.
Stefan Jansen
8,974 Pointsthats great, but you need to add something behind it, otherwise you get parse errors!
Matt Trask
10,027 Pointswhat do you mean something behind it? Im on paypayl right now getting the id codes.
Jacques Vincilione
17,292 PointsJust make sure you add the values to the array. And remove the include from products.php.
Stefan Jansen
8,974 Pointsplease google php parse error, it's seams you don't understand this basic programming subject.
Have a look at the example product I made. You need to save the products like that, if you want your code to work.
Jacques Vincilione
17,292 PointsHe's taking a basic PHP course...
Matt Trask
10,027 PointsI figured it out. Jacques helped me realize that including products.php on the products.php was what messed it up. Once I removed it, it all worked. Thanks for the help everyone!
Jacques Vincilione
17,292 PointsGlad we could help!