1
votes

I've created my shopping cart which works perfectly for adding multiple items. This will then loop over each item and display the image, name, quantity and total price.

I have added a paypal button and am trying to get this to work but I'm not sure why it isn't picking anything up. I always get 'Error Detected, nothing in shopping cart'.

I also print out my variables to ensure they are correct which they are, but still looks like it's not getting picked up in the form.

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="[email protected]">

for ($i = 0; $i < count($cart); $i++) {
         $s += $cart[$i]->price * $cart[$i]->quantity;
         $ppName = $cart[$i]->name;
         $ppAmount = $cart[$i]->price * $cart[$i]->quantity;
         $ppQuantity = $cart[$i]->quantity;
         // Inside of for each loop 
         ?>  
         <input type="hidden" name="item_name_<?php echo $x; ?>" value="<?php echo $ppName; ?>">
         <input type="hidden" name="amount_<?php echo $x; ?>" value="<?php echo $ppAmount; ?>">
         <input type="hidden" name="quantity_<?php echo $x; ?>" value="<?php echo $ppQuantity; ?>">
         <tr>
         <td class="col-md-2"><img class="img-responsive" img src= '<?php echo $cart[$i]->image_name; ?>' alt="Oops, Image cannot be found!" height="150" width="150"/></td>
         <td class="col-md-4">Name: <?php echo $cart[$i]->name; ?><br><br> <?php echo $cart[$i]->description; ?></td>
         <td class="col-md-4"> <a href="checkout.php?index=<?php echo $index; ?>" onclick="return confirm('Are you sure?')"><span class="glyphicon glyphicon-minus"></a></span> Qty <?php echo $cart[$i]->quantity; ?> <span class="glyphicon glyphicon-plus"></span></td>
         <td><?php echo $cart[$i]->price * $cart[$i]->quantity; ?></td>         
         </tr>
         <br>
         <?php
         $index++;
         $x = $i + 1;
         ?>

 <input type="hidden" name="currency_code" value="GBP">
 <input type="hidden" name="hosted_button_id" value="2R2BAJEWK3LRU">
 <input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
 <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">

I would appreciate any feedback. Many thanks.

1

1 Answers

0
votes

I found the hosted_button_id contained in your button code, once the hotsted button id is contained, all of the extra codes you added are invalid.

Please delete the line of "hosted_button_id" and retry it.