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

Understanding Whitespace

This is not a code challenge thing, it's more of a following along issue here.

I just got done with Understanding Whitespace and did the code as Mr. Hoyt showed (best that I know) and when I get my code done, unlike Mr. Hoyt who gets his page to display, I get this:

Parse error: syntax error, unexpected ''" alt="'' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in C:\xampp\htdocs\shirts.php on line 60

Here's the code, I'm gonna go back to take a look at what I done wrong in a few:

<?php

$products = array(); $products[101] = array( "name" => "Logo Shirt, Red", "img" => "img/shirts/shirt-101.jpg", "price" => 18
); $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 );

?><?php $pageTitle = "Mike's T-Shits"; $section = "shirts"; include('inc/header.php'); ?>

  <div class="section page">

     <div class="wrapper">

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

     <ul class="products">
        <?php foreach($products as $product) 
            echo "<li>";
            echo '<a href="#">';
            echo '<img src="' . $product["img"]'" alt="' . $product["name"]'">';
            echo "</li>"
            echo "<p>View Details</p>"
            echo "</a>"
        } 
     ?>
     </ul>

  </div>

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

4 Answers

    <?php foreach($products as $product) 
               echo "<li>";
               echo '<a href="#">';
               echo '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
               echo "<p>View Details</p>";
               echo "</a>";
               echo "</li>";
           } 
        ?>

3 things Robert:

  • in your foreach ($products as $product) you were missing the semicolons as Dai pointed out.
  • in your foreach, You are also missing the beginning curly brace for it.
  • in your foreach, you're missing a . between the variable $product["img"] and the string '" alt="'

Make sure you double and triple check your syntax

It looks like you are missing a couple concatenation periods on the third line of your foreach loop (one between $product["img"] and '" alt="' and I'll let you find the other).

I took a look at the download they provide and saw what I did wrong as Dai Phong pointed out. Syntax!