please please help
i have built a shopping cart which works, my problem is passing multiple items to paypal. i can send one item no problem but when i try to send 2 or more items paypal shows 14 items called array.
please look at my code any help greatly appreciated.
i am sure it is a problem with the while and for loops not sending the correct info.

<html>
<body>
<form target= "paypal" 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 ="me@me.co.uk">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="shipping" value="4.95">
<input type="hidden" name="shipping2" value="0.00">
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but02.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<form>

<?php
session_start();

//connect to database
$mysqli = mysqli_connect("me", "me", "me", "me");

$display_block = "<td align=\"center\"><h1>Your Shopping Cart</h1>";

//check for cart items based on user session id
$get_cart_sql = "SELECT st.id, si.item_title, si.item_price, st.sel_item_qty, st.sel_item_size, item_image, st.sel_item_color FROM store_shoppertrack AS st LEFT JOIN store_items AS si ON si.id = st.sel_item_id WHERE session_id = '".$_COOKIE["PHPSESSID"]."'";
$get_cart_res = mysqli_query($mysqli, $get_cart_sql) or die(mysqli_error($mysqli));



if (mysqli_num_rows($get_cart_res) < 1) {
    //print message
    $display_block .= "<p>You have no items in your cart.
    Please <a href=\"index.html\">continue to shop</a>!</p>";
} else {
    //get info and build cart display
    $display_block .= "
    <table border=\10 width=\"76%\"bgcolor=\"#FFCCFF\"<td align=\"center\">
    <tr>
	<th>Image</th>
    <th>Title</th>
    <th>Size</th>
    <th>Color</th>
    <th>Price</th>
    <th>Qty</th>
    <th>Total Price</th>
    <th>Action</th>
    </tr>";


while ($cart_info = mysqli_fetch_array($get_cart_res)) {

    $id = $cart_info['id'];
    $item_title = stripslashes($cart_info['item_title']);
    $item_price = $cart_info['item_price'];
    $item_qty = $cart_info['sel_item_qty'];
    $item_color = $cart_info['sel_item_color'];
    $item_size = $cart_info['sel_item_size'];
    $total_price = sprintf("%.02f", $item_price * $item_qty);
	$Sub_Total =  sprintf("%.02f", $total_price)+($Sub_Total);
	$item_image = $cart_info['item_image'];

 //this i believe is the problem

 for($i=0; $i < count($get_cart_res); $i++){
$val = $i + 1;
echo "<input type=\"hidden\" name=\"quantity_$val\" value=\"$item_qty\">";
echo "<input type=\"hidden\" name=\"item_name_$val\" value=\"$item_title\">";
echo "<input type=\"hidden\" name=\"amount_$val\" value=\"$item_price\">";


}



}





    $display_block .= "
    <tr>
	<td align=\"center\"><img src=\"".$item_image."\"/></td>
    <td align=\"center\">$item_title <br></td>
    <td align=\"center\">$item_size <br></td>
    <td align=\"center\">$item_color <br></td>
    <td align=\"center\">£ $item_price <br></td>
    <td align=\"center\">$item_qty <br></td>
    <td align=\"center\">£ $total_price</td>
    <td align=\"center\"><a href=\"removefromcart.php?id=".$id."\">remove</a></td>
    </tr>";

}


{
$display_block .= "
<tr>
		<th><td align=\"right\"><strong>Sub Total</strong></th>
		<td align=\"right\">£ $Sub_Total</td>
		</td>";
    $display_block .= "</table>";
	}

?>

<title>My Store</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
h1,h2,h3,h4,h5,h6 {
font-family: Palatino Linotype;
}
h1 {
font-size: 24px;
color: #FF99FF;
text-align: center;
}
body {
background-image: url(images/heart4.jpg);
}
-->
</style></head>

<p align="center"><img src="images/sensual.jpg" width="520" height="104"></p>
<p align="center"><?php echo $display_block; ?></p>
<p align="center"> Free Delivery on all orders over &pound;100</p>

<form name="form1" method="post" action="index.html">
<label>
<div align="center">
<input type="submit" name="Submit" value="Continue Shopping">
</div>
</label>
</form>
<p>&nbsp;</p>
<p>
</p>

</body>
</html>

    Load this script in your browser, then go to View > Source in your browser to see the resulting HTML produced by your script. Is the Paypal code properly formatted there?

    If not, then where specifically is the problem occurring? That will help us pinpoint what in your script needs to be adjusted.

      Thanks for the reply.
      This has been driving me mad for days. the problem I believe lies in this part of the code

      while ($cart_info = mysqli_fetch_array($get_cart_res)) {
      
             $id = $cart_info['id'];
             $item_title = stripslashes($cart_info['item_title']);
             $item_price = $cart_info['item_price'];
             $item_qty = $cart_info['sel_item_qty'];
             $item_color = $cart_info['sel_item_color'];
             $item_size = $cart_info['sel_item_size'];
          $total_price = sprintf("%.02f", $item_price * $item_qty);
          $Sub_Total =  sprintf("%.02f", $total_price)+($Sub_Total);
          $item_image = $cart_info['item_image'];
      
      //this i believe is the problem
      
      for($i=0; $i < count($get_cart_res); $i++){
      $val = $i + 1;
      echo "<input type=\"hidden\" name=\"quantity_$val\" value=\"$item_qty\">";
      echo "<input type=\"hidden\" name=\"item_name_$val\" value=\"$item_title\">";
      echo "<input type=\"hidden\" name=\"amount_$val\" value=\"$item_price\">";
      

      I have tried changing various variables in the FOR statement all with varying results. as i said before it sends one item correctly but when i add a second item to my cart and try to send both items i get strange results varying from nothing at all to 14 entries all called array the price and qty remain the same.

      the correct format to upload the code to paypal is:

      <form target= "paypal" 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 ="me@me.co.uk">
      <input type="hidden" name="currency_code" value="GBP">
      <input type="hidden" name="shipping" value="4.95">
      <input type="hidden" name="shipping2" value="0.00">
      <input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but02.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
      <form>
      

      all i have done is extract the 3 values of item name, price and quantity and put it into the script which paypal recieves on one item.
      I know it can be done as many others have succeded but the paypaldev forum is not very helpful as they keep referring you to generic code which i have already implemented.

      if you can help it would be greatly appreciated.

        the paypal code seems to be set up ok as it sends one item correctly.
        my problem is sending two or more items.
        I am trying using the following code.

        while ($cart_info = mysqli_fetch_array($get_cart_res)) { 
        
               $id = $cart_info['id']; 
               $item_title = stripslashes($cart_info['item_title']); 
               $item_price = $cart_info['item_price']; 
               $item_qty = $cart_info['sel_item_qty']; 
               $item_color = $cart_info['sel_item_color']; 
               $item_size = $cart_info['sel_item_size']; 
            $total_price = sprintf("%.02f", $item_price * $item_qty); 
            $Sub_Total =  sprintf("%.02f", $total_price)+($Sub_Total); 
            $item_image = $cart_info['item_image']; 
        
        //this i believe is the problem 
        
        for($i=0; $i < count($get_cart_res); $i++){ 
        $val = $i + 1; 
        echo "<input type=\"hidden\" name=\"quantity_$val\" value=\"$item_qty\">"; 
        echo "<input type=\"hidden\" name=\"item_name_$val\" value=\"$item_title\">"; 
        echo "<input type=\"hidden\" name=\"amount_$val\" value=\"$item_price\">"; 

        the for statement was written by myself and with one item in my cart it works fine
        i need to know how to get it to send other items if added to my cart i have tried various options including.

        for($i=0; $i < count($get_cart_res); $i++){ 
        $val = $i + 1; 
        echo "<input type=\"hidden\" name=\"quantity_$val\" value=\"$item_qty[$i]\">"; 
        echo "<input type=\"hidden\" name=\"item_name_$val\" value=\"$item_title[$i]\">"; 
        echo "<input type=\"hidden\" name=\"amount_$val\" value=\"$item_price[$i]\">"; 

        all variations to the above code send differing results to paypal.

        what i need is code that will load all my cart items to paypal.

        any help greatly appreciated.

          8 days later

          I have finally sorted it out.

          I will post the code if anyone is interested.

          many thanks

            a month later

            I'm interested in the code. Having issues along same line. thanks!

              Write a Reply...