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 trialpedro león
Courses Plus Student 54 PointsPorblem with $product
<?php include ("Include/products.php");
$product_id = $_GET["id"];
$product = $products[$product_id];
include("Include/header.php"); ?>
<div class="section page">
<div class="wrapper">
<div class="breadcrumb"><a href="tshirt.php">Shirts</a><?php echo $product["name"]; ?></div>
<div class="shirt-picture">
<span>
<img src="<?php echo $product["img"]; ?>" alt="<?php echo $product["name"]; ?>">
</span>
</div>
<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="SQRK6TCAPR47S">
<input type="hidden" 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">
<option value="Small">Small $180.00 MXN</option>
<option value="Medium">Medium $180.00 MXN</option>
<option value="Large">Large $180.00 MXN</option>
<option value="X-Large">X-Large $180.00 MXN</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="MXN">
<input type="submit" value="Add to cart" border="0" name="submit">
<img alt="" border="0" src="https://www.paypalobjects.com/es_XC/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
</div>
<?php include("Include/footer.php"); ?>
When i start the web it says this "Notice: Undefined index: $product in C:\xampp\htdocs\shirt.php on line 4" i check the correct form in the downloads and still nothing when make the corrections
1 Answer
Philip Harper
10,033 PointsLooks like your syntax for $product = $products[$product_id]; isn't quite right.
What type of array is it supposed to be?
Indexed arrays - Arrays with a numeric index Associative arrays - Arrays with named keys Multidimensional arrays - Arrays containing one or more arrays
—
try $product = $products => [$product_id];