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 Adding Available Sizes

Why won't shirt sizes pop up?

I have no clue here are my two files.

products.php

<?php
$products = array();

$products[101] = array(
    "name" => "Logo Shirt, Red",
    "img" => "img/shirts/shirt-101.jpg",
    "price" => 18, 
    "paypal" => "P92T46BGE6Z5Q",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[102] = array(
    "name" => "Mike the Frog Shirt, Black",
    "img" => "img/shirts/shirt-102.jpg",
    "price" => 20,
    "paypal" => "ZV3388WCHG7CN",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[103] = array(
    "name" => "Mike the Frog Shirt, Blue",
    "img" => "img/shirts/shirt-103.jpg",    
    "price" => 20,
    "paypal" => "73T4U4ESTFCGW",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[104] = array(
    "name" => "Logo Shirt, Green",
    "img" => "img/shirts/shirt-104.jpg",    
    "price" => 18,
    "paypal" => "QP3T8RJ2JGLJ6",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[105] = array(
    "name" => "Mike the Frog Shirt, Yellow",
    "img" => "img/shirts/shirt-105.jpg",    
    "price" => 25,
    "paypal" => "JPNA6HQS4R6AC",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[106] = array(
    "name" => "Logo Shirt, Gray",
    "img" => "img/shirts/shirt-106.jpg",    
    "price" => 20,
    "paypal" => "9U8XDFY7PCVYW",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[107] = array(
    "name" => "Logo Shirt, Turquoise",
    "img" => "img/shirts/shirt-107.jpg",    
    "price" => 20,
    "paypal" => "BK6EVECGZ78XG",
    "sizes" => array("Small","Medium","Large","X-Large");
);

$products[108] = array(
    "name" => "Logo Shirt, Orange",
    "img" => "img/shirts/shirt-108.jpg",    
    "price" => 25,
    "paypal" => "886DTRMT4K7UC",
    "sizes" => array("Large","X-Large");
);

?>

shirt.php

<?php 
include ('INC/products.php'); 

if (isset($_GET["id"])) {

    $product_id = $_GET["id"];

    if (isset($products[$product_id])) {

        $product = $products[$product_id];

    }

} 

if (!isset($product)) {

    header("Location: shirts.php");

    exit();

}

$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 class="shirt-details">

                <h1> 

                    <span class="price"> $

                        <?php echo $product["price"]; ?>

                    </span>

                         <?php echo $product["name"]; ?> 

                </h1>

                <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">

                    <input type="hidden" name="cmd" value="_s-xclick">

                    <input type="hidden" name="hosted_button_id" value="<?php echo $product["paypal"]?>">

                    <input type="hidden" name="item_name" value="<?php echo $product["name"]?>">

                        <table>

                            <tr>

                                <th> 

                                    <input type="hidden" name="on0" value="Size"> 

                                    <label for="os0"> Size </label> 

                                </th>

                                <td> 

                                    <select name="os0" id="os0">

                                         <?php foreach($product["sizes"] as $size) { ?>

                                             <option value="<?php echo $size; ?>"><?php echo $size; ?> </option>

                                         <?php } ?>

                                    </select> 

                                </td>

                            </tr>

                        </table>

                    <input type="submit" value="Add To Cart" name="submit">

                </form>

                <p class="note-designer"> *All Shirts Are Designed By Mike The Frog. </p>

            </div>

        </div>

    </div>

<?php include ("INC/footer.php"); ?>

Formatted to distinguish files.

I will have to compare my work on when I am on my computer. I am going to start by looking at your for each loop.

2 Answers

If you look at this code section:

<?php
if (isset($_GET["id"])) {

    $product_id = $_GET["id"];

    if (isset($products[$product_id])) {

        $product = $products[$product_id];

    }

} 

you will see that both if statements are isset. I think the first should be !isset.

The second one is supposed to be !isset not any other ones, I would really like to continue this exercise.

You have a syntax error in your code, which is located within the products.php file.

Each product element array => size array is ending with a semi-colon ( ; ). Remove this from the end of every size array, and your code should then run without any errors.