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

Imon Dela Rosa
Imon Dela Rosa
7,383 Points

Please help. Sizes are not showing on shirt.php page after changing from html tag to php script.

...<select name="os0" id="os0"><option value="Small">Small</option> <option value="Medium">Medium</option> <option value="Large">Large</option> <option value="X-Large">X-Large</option> </select>...

Any help would be greatly appreciated. Thanks

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,671 Points


Please post your code so we can better help you.

Imon Dela Rosa
Imon Dela Rosa
7,383 Points

HI! Rich, Unfortunately, it won't let me post the codes here. I have seen the problem through chrome dev tools. Because I didn't setup an Paypal Business Account and I think the script is looking for paypal user info?

<input type="hidden" name="hosted_button_id" value="<br /> <b>Notice</b>: Undefined index: paypal in <b>/Applications/MAMP/htdocs/shirts4mike/shirt.php</b> on line <b>38</b><br /> ">

script: <select name="os0" id="os0"> <?php foreach($product["sizes"] as $size) { ?> <option value="<?php echo $size; ?>"><?php echo $size; ?></option> <?php } ?> </select>

1 Answer

Adam Young
Adam Young
15,791 Points

It's related to not having a Paypal account set up, in a sense. In inc/products.php, every shirt's array includes a "paypal" key.

Check it out:

From products.php:

$products[101] = array(
    "name" => "Logo Shirt, Red",
    "img" => "img/shirts/shirt-101.jpg",
    "price" => 18,
    "paypal" => "I CAN LITERALLY PUT ANYTHING HERE(figuratively, of course)",
    "sizes" => array("Small","Medium","Large","X-Large")

Then, from shirt.php:

<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"]; ?>"> //Problem is here!

You can either assign the paypal key a value or remove it from value of the hidden field. Hope this helps!

Edit: This is specifically for the Notice you received. We can dig further if you can find a way to paste your code.

Imon Dela Rosa
Imon Dela Rosa
7,383 Points

Thank you Adam, you are right. I had a problem with products.php. For some reason I didn't realize I created 2 files of products.php into shirt4mike folder and inside the inc folder and my shirt.php was pointing to inc/products.php who hasn't array key value for paypal rather than the other one. I checked using var_dump and a result of null.