Schlo_50 Posted March 20, 2008 Share Posted March 20, 2008 I am using a php shopping cart and would like to upload the entire contents of the cart to Paypal when the user is ready to checkout, including the individual item title/description and price. I gather that the code I need to put on my checkout button is as follows: <form action="https://www.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]"> <input type="hidden" name="item_name_1" value="Item Name 1"> <input type="hidden" name="amount_1" value="1.00"> <input type="hidden" name="item_name_2" value="Item Name 2"> <input type="hidden" name="amount_2" value="2.00"> <input type="submit" value="PayPal"></form> However, I don't want to have to hard code the items and amounts, but would prefer to have a loop that runs for the item_name and amount incrementing the names (item_name_x and amount_x) and passing in the values using my variables ($item_title and $item_price). If I have $item as the variable for individual items put in the shopping cart and $price as the variable for their prices does anybody have an snippet example of the loop I need to use along with the above paypal form please? Im just not sure how to loop and increment the form names together. Help! Please? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/97040-loops-and-paypal/ Share on other sites More sharing options...
Schlo_50 Posted March 20, 2008 Author Share Posted March 20, 2008 I have the following loop for $item and $price but im not sure how to increment the form in the loop too? Anyone got any idea? foreach($bcartfile as $bKey => $Val){ $Data[$bKey] = explode("|", $Val); $item = $Data[$bKey][0]; $pid = $Data[$bKey][1]; $price = $Data[$bKey][2]; $bstr = $cartfile[$bKey]; $bstr = explode('|', $str); $btotal += $bstr[2]; $fulltotal = $total+$pprice; print "<tr>"; print "<td width=\"65%\" valign=\"top\">$item</td>"; print "<td width=\"35%\" valign=\"top\"><p align=\"right\">£$price</p></td>"; print "</tr>"; } Thanks Link to comment https://forums.phpfreaks.com/topic/97040-loops-and-paypal/#findComment-496591 Share on other sites More sharing options...
Schlo_50 Posted March 20, 2008 Author Share Posted March 20, 2008 Can someone help me with the loop. I have had a go but need some help tweaking I think. for($i = 1; $i < $item; $i++) { $z = "item_name_$i"; $y = "amount_$i"; } print "<input type=\"hidden\" name=\"$z\" value=\"$item\">"; print "<input type=\"hidden\" name=\"$y\" value=\"$price\">"; Link to comment https://forums.phpfreaks.com/topic/97040-loops-and-paypal/#findComment-496593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.