Hi everyone.
I have built a website in
php and everything is working ok, I have mysql, apache and
php all behaving themselves, my problem lies with paypal not recieving all the items in my cart. If I add one item to my cart and check out to paypal there is no problem, if i add a second item and checkout it recieves the second but not the first in other words it doesnt seem to recieve (i think) all items held in that session.
please take a look at my code.
- PHP: Select all
<?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>";
}
?>
I think the for statement above may need tweaking but my tweaking has all tweaked out and I am now stumped and need help, lots of it.
Thanks in advance for any help or pointers.