for loop - php cart not sending through more than one item to paypal -
i have created cart , reason not adding item paypal. sends 1 item. have list of items added in database , loop through them.
<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="test@test.com" /> <div class="basket_block" id="basket_block"> <div class="checkout_inv" id="checkout_inv">invoice: oca1234</div> <?php $sql_cart="select * cart_table session_id = '$sessionid'"; $result_set_cart=$database->query($sql_cart); $num_rows_cart=$database->num_rows($result_set_cart); for($i=1;$i<=$num_rows_cart;$i++) { while ($row_cart=$database->fetch_array($result_set_cart)){ $prod_id_now=$row_cart['products_id']; $quantity_now=$row_cart['quantity']; $grand_total_now =$row_cart['grand_total']; $sql_product = "select * products id = '$prod_id_now'"; $result_set_product = $database->query($sql_product); while ($row_product=$database->fetch_array($result_set_product)){ $titleofmessage = $row_product['title_of_message']; $type_id = $row_product['type_id'];} $sql_type = "select * type id = '$type_id'"; $result_set_type = $database->query($sql_type); while ($row_type=$database->fetch_array($result_set_type)){ $typename = $row_type['name'];} ?> <div class="checkout_des" id="checkout_des"> <?php echo 'title: '.html_entity_decode($titleofmessage).'<br>'.'tpye: '.$typename.'<br>'.'quantity: '.$quantity_now."<p>"; ?></div> <div class="checkout_amount" id="checkout_amount"><?php echo 'r '.number_format($grand_total_now,2); ?></div> <input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo html_entity_decode($titleofmessage); ?>" /> <input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $quantity_now; ?>" /> <input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $grand_total_now; ?>" /> <?php } } ?> </div>
just add $i++; need increment loop
<div class="checkout_amount" id="checkout_amount"><?php echo 'r '.number_format($grand_total_now,2); ?></div> <input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo html_entity_decode($titleofmessage); ?>" /> <input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $quantity_now; ?>" /> <input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $unit_cost; ?>" /> <?php $i++; } } ?>
Comments
Post a Comment