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 Including the Products Array

Cant get the concatenation to work

<?php include("inc/products.php"); ?><?php
$pageTitle = "Unique t-shirts";
$section = "shirts";
include('inc/header.php'); ?>

<div class="section shirts page">
  <div class="wrapper">

  <h1>Mikes&rsquo;s Full Catalog 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'); ?>

I formatted your code for readabiliity.

Please see this thread for posting code to the forum. :)

6 Answers

Then you must have an error elsewhere in the code, can you please post the contents of products.php, header.php and footer.php files as well? I will quickly check them for you :)

It must be a typo :) also place this on the very top of your code:

<?php
// Enables error reporting
error_reporting(E_ALL);
ini_set("display_errors", 1);

include("inc/products.php");
// Rest of yout code goes here...
?>

It should show php errors instead of a blank page :)

Thank you, that error code showed the issue. Was issue in products.php page, Now it works =)

Glad I could help, it's good practice to have error reporting ON while in development - saves you a lot of time :)

Good luck for the fututre!

Kind regards, Maciej Sularz

what is the issue? I have set up the products file and shirt file. But when i click on a image i only come to this link: http://port-80-o8ngbeg2s8.treehouse-app.com/shirts.php

On line 15 :

echo'<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'

you forgot the semi-colon at the end of the line. That's all. :)

<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>

Still doesnt work

Hmm. I just tested against my Shirts4Mike project and it worked after I added the semi-colon.

What error are you getting or what shows up on the page?

You are missing a semicolon at the end of the line after <img> tag in your <ul> element.

Let me know if that solves the problem :)

<?php

echo'<img src="' . $product["img"] . '" alt="' . $product["name"] . '">'

?>

It didnt solve it

It comes up a white blank page on this url: http://port-80-o8ngbeg2s8.treehouse-app.com/shirts.php

Try this code, is the $products defined in the header?

<ul class="products">
        <?php
        $products = array(
            array(
                'img' => 'http://placehold.it/150x150',
                'name' => 'Product 1 Name'),
            array(
                'img' => 'http://placehold.it/150x150',
                'name' => 'Product 1 Name'),
            array(
                'img' => 'http://placehold.it/150x150',
                'name' => 'Product 1 Name')
        );
      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>

No, still same.

No, still same.

Do any other pages load correctly from the project's workspace, like the index?