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

PHP Build a Simple PHP Application Integrating with PayPal Building the Shirt Details Page

shirt.php not working

So I'm working on shirt.php, and the Image, page title, and breadcrumb are not displaying. I downloaded the project files and they worked. Here's shirt.php :

<?php 
include('inc/products.php');
 $product_id = $GET["id"];
 $product = $products[$product_id];

 $section = "shirts";
 $pageTitle = $product["name"];
 include("inc/header.php");

?>

  <div class="section page">

    <div class="wrapper">

      <div class="breadcrumb"><a href="shirts.php">Shirts</a> &gt; <?php echo $product["name"]; ?> </div>

      <div class="shirt-picture">
        <span>
          <img src="<?php echo $product["img"]; ?>" alt=" <?php echo $product["name"];  ?>">
        </span>
      </div>

    </div>

  </div>

<?php include('inc/footer.php'); ?>

shirts.php

<?php 
 include("inc/products.php");
?><?php

$pageTitle = "Mikes Full Catalog of Shirts";
$section = "shirts";
include('inc/header.php') ?>

    <div class="section shirts page">

      <div class="wrapper">

         <h1>Mike&rsquo;s Full Catolog Of Shirts</h1>

         <ul class="products">
        <?php foreach($products as $product_id => $product) { 
               echo "<li>";
               echo '<a href="shirt.php?id=' . $product_id . '">';
               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') ?>

products.php

<?php
$products = array();
$products[101] = array(
  "name" => "Logo Shirt, Red",
  "price" => 18,
  "img" => "img/shirts/shirt-101.jpg"
);
$products[102] = array(
  "name" => "Mike the Frog Shirt, Black",
    "img" => "img/shirts/shirt-102.jpg",
    "price" => 20
);
$products[103] = array(
    "name" => "Mike the Frog Shirt, Blue",
    "img" => "img/shirts/shirt-103.jpg",    
    "price" => 20
);
$products[104] = array(
    "name" => "Logo Shirt, Green",
    "img" => "img/shirts/shirt-104.jpg",    
    "price" => 18);
$products[105] = array(
    "name" => "Mike the Frog Shirt, Yellow",
    "img" => "img/shirts/shirt-105.jpg",    
    "price" => 25
);
$products[106] = array(
    "name" => "Logo Shirt, Gray",
    "img" => "img/shirts/shirt-106.jpg",    
    "price" => 20
);
$products[107] = array(
    "name" => "Logo Shirt, Turquoise",
    "img" => "img/shirts/shirt-107.jpg",    
    "price" => 20
);
$products[108] = array(
    "name" => "Logo Shirt, Orange",
    "img" => "img/shirts/shirt-108.jpg",    
    "price" => 25,
);

?>

4 Answers

David Rynn
David Rynn
10,554 Points

Er, shouldn't line 3 of shirt.php be:

$product_id = $_GET["id"];

with an underscore, not

$product_id = $GET["id"];

Yes it should.

Well I'm not quite sure what I did, but it works now. And I better understand how that code works. I think it may have been a problem with localhost.

Oh and I haven't done any pay-pal stuff to it yet.

Hugo Paz
Hugo Paz
15,622 Points

Hi Carman,

Does shirts.php work or are you only having issues in shirt.php?

Thanks for replying! shirts.php works. And as far as I'm aware the only problem site-wide is shirt.php.