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

redirecting-invalid-shirt-ids not redirecting

I've been following this php 'Shirts 4 Mike' tutorial very closely, and all my code has functioned as predicted up until now. For some reason, although my code seems to be identical to Randy's, the redirect on erroneous or missing shirt id doesn't function: my page is just left blank. I've included the relevant section of code (nothing'd been modified since functioning properly):

<?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"); ?>

Well I'm not sure what's happened, but it seems to be functioning now. Thanks for all the help you active community of users you!

2 Answers

Ron McCranie
Ron McCranie
7,837 Points

Looks like it might have been the semi-colon at the end of this line header("Location: shirts.php"): you had a colon in the code you pasted.

Really! So hard to find little things in the code sometimes. Thanks for your hawk vision Ron!