I’m just trying to add a size variable to the IPN so when the client receives the order information, they can view what size was requested, so far I’ve added this to my button:
[code=php]<input type=”hidden” name=”on0″ value=”CustomID”>
<input type=”hidden” name=”os0″ value=”echo $size[size]”>
and this to the IPN
[code=php]$customid = $_POST[‘option_selection1’];
as well as updating the database INSERT, can anyone see any reason why this wouldn’t work properly as I’m having trouble with it, here is the cart page
[code=php]<?php
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
?>
<?php
if (isset($_POST[‘pid’])) {
$pid = $_POST[‘pid’];
$size = $_POST[‘size’];
$wasFound = false;
$i = 0;
// If the cart session variable is not set or cart array is empty
if (!isset($_SESSION[“cart_array”]) || count($_SESSION[“cart_array”]) < 1) {
// RUN IF THE CART IS EMPTY OR NOT SET
$_SESSION[“cart_array”] = array(1 => array(“item_id” => $pid, “size” => $size, “quantity” => 1));
} else {
// RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
foreach ($_SESSION[“cart_array”] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == “item_id” && $value == $pid){
if ($each_item[‘size’] == $size){
// That item is in cart already so let’s adjust its quantity using array_splice()
array_splice($_SESSION[“cart_array”], $i-1, 1, array(array(“item_id” => $pid, “size” => $size, “quantity” => $each_item[‘quantity’] + 1)));
$wasFound = true;
}} // close if condition
} // close while loop
} // close foreach loop
if ($wasFound == false) {
array_push($_SESSION[“cart_array”], array(“item_id” => $pid,”size” => $size, “quantity” => 1));
}
}
header(“location: cart.php”);
exit();
}
?>
<?php
if (isset($_GET[‘cmd’]) && $_GET[‘cmd’] == “emptycart”) {
unset($_SESSION[“cart_array”]);
unset($_SESSION[“tradesrgr”]); //unset all sessions if cart is empty
unset($_SESSION[‘amount’]); //unset all sessions if cart is empty
unset($_SESSION[‘final’]);//unsets user cart cartTotal
}
?>
<?php
if (isset($_POST[‘item_to_adjust’]) && $_POST[‘item_to_adjust’] != “”) {
// execute some code
$item_to_adjust = $_POST[‘item_to_adjust’];
$size = $_POST[‘size’];
$quantity = $_POST[‘quantity’];
$quantity = preg_replace(‘#[^0-9]#i’, ”, $quantity); // filter everything but numbers
if ($quantity >= 100) { $quantity = 99; }
if ($quantity < 1) { $quantity = 1; }
if ($quantity == “”) { $quantity = 1; }
$i = 0;
foreach ($_SESSION[“cart_array”] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == “item_id” && $value == $item_to_adjust) {
if ($each_item[‘size’] == $size){
// That item is in cart already so let’s adjust its quantity using array_splice()
array_splice($_SESSION[“cart_array”], $i-1, 1, array(array(“item_id” => $item_to_adjust, “size” => $size, “quantity” => $quantity)));
} // close if condition
} // close while loop
} // close foreach loop
}
}
?>
<?php
if (isset($_POST[‘index_to_remove’]) && $_POST[‘index_to_remove’] != “”) {
// Access the array and run code to remove that array index
$key_to_remove = $_POST[‘index_to_remove’];
if (count($_SESSION[“cart_array”]) <= 1) {
unset($_SESSION[“cart_array”]);
unset($_SESSION[‘final’]);//unsets user cart cartTotal
} else {
unset($_SESSION[“cart_array”][“$key_to_remove”]);
sort($_SESSION[“cart_array”]);
}
}
?>
<?php
// Connect to the MySQL database
require “storescripts/connect_to_mysql.php”;
$myConnection= mysqli_connect(“$db_host”,”$db_username”,”$db_pass”, “$db_name”) or die (“could not connect to mysql”);
$note=””;
$Empty = “”;
$cartOutput = “”;
$cartTotal = “”;
$pid = “”;
$product_name = “”;
$price = “”;
$pp_checkout_btn = ”;
$product_id_array = ”;
$amount=”;
$details=”;
$size=”;
if (!isset($_SESSION[“cart_array”]) || count($_SESSION[“cart_array”]) < 1) {
$Empty = “<br/>Your shopping cart is empty<br/>”;
} else {
// Start PayPal Checkout Button
$pp_checkout_btn .= ‘<form action=”https://www.paypal.co.uk/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=”#@gmail.com”>’;
// Start the For Each loop
$i = 0;
foreach ($_SESSION[“cart_array”] as $each_item) {
$item_id = $each_item[‘item_id’];
$sql = mysql_query(“SELECT * FROM products WHERE id=’$item_id’ LIMIT 1”);
while ($row = mysql_fetch_array($sql)) {
$pid = $row[“id”];
$product_name = $row[“product_name”];
$price = $row[“price”];
$details = $row[“details”];
}
$pricetotal = $price * $each_item[‘quantity’];
$cartTotal = $pricetotal + $cartTotal;
setlocale(LC_MONETARY, “en_GB”);
$pricetotal = money_format(“%!4.2n”, $pricetotal);
// Dynamic Checkout Btn Assembly
$x = $i + 1;
$pp_checkout_btn .= ‘<input type=”hidden” name=”item_name_’ . $x . ‘” value=”‘ . $product_name . ‘”>
<input type=”hidden” name=”amount_’ . $x . ‘” value=”‘ . $price . ‘”>
<input type=”hidden” name=”size_’. $x . ‘” value=”‘. $each_item[‘size’] . ‘”>
<input type=”hidden” name=”quantity_’ . $x . ‘” value=”‘ . $each_item[‘quantity’] . ‘”> ‘;
// Create the product array variable
$product_id_array .= “$item_id-“.$each_item[‘quantity’].”,”;
// Dynamic table row assembly
$cartOutput .= “<tr>”;
$cartOutput .= ‘<td><a href=”product.php?id=’ . $item_id . ‘”>’ . $product_name . ‘</a><br /><img src=”../inventory_images/’ . $item_id . ‘.jpg” alt=”‘ . $product_name. ‘” width=”40″ height=”52″ border=”1″ /></td>’;
$cartOutput .= ‘<td>’ . $pid . ‘</td>’;
$cartOutput .= ‘<td>’ . $product_name .'</td>’;
$cartOutput .= ‘<td>’ . $each_item[‘size’] .'</td>’;
$cartOutput .= ‘<td>£’. $price . ‘</td>’;
$cartOutput .= ‘<td><form action=”cart.php” method=”post”>
<input name=”quantity” type=”text” value=”‘ . $each_item[‘quantity’] . ‘” size=”1″ maxlength=”2″ />
<input name=”adjustBtn’ . $item_id . ‘” type=”submit” value=”change” />
<input name=”item_to_adjust” type=”hidden” value=”‘ . $item_id . ‘” />
<input name=”size” type=”hidden” value=”‘ . $each_item[‘size’] . ‘” />
</form></td>’;
//$cartOutput .= ‘<td>’ . $each_item[‘quantity’] . ‘</td>’;
$cartOutput .= ‘<td>£’.$pricetotal.'</td>’;
$cartOutput .= ‘<td><form action=”cart.php” method=”post”><input name=”deleteBtn’ . $item_id . ‘” type=”submit” value=”X” /><input name=”index_to_remove” type=”hidden” value=”‘ . $i . ‘” /></form></td>’;
$cartOutput .= ‘</tr>’;
$i++;
$loop = $i ;
$count = $cartTotal;
if ($loop == 1 ){
$_SESSION[‘final’] = $count;
}else if ($loop > 1 ){
$display = $_SESSION[‘final’];
$count2 = $display;
$display = $count2 = $count;
$_SESSION[‘final’] = $display;
}
$show = $_SESSION[‘final’];
$count .= ”.$i.”;
$items_in_cart=’Current Spend <strong>£’ . $show;
}
setlocale(LC_MONETARY, “en_GB”);
$cartTotal = money_format(“%!10.2n”, $cartTotal);
$cartTotal = “<div style=’font-size:18px; margin-top:12px;’ align=’right’>Cart Total : £”.$cartTotal.” GBP
<p></p></div>”;
// Finish the Paypal Checkout Btn
$pp_checkout_btn .= ‘<input type=”hidden” name=”custom” value=”‘ . $product_id_array . ‘”>
<input type=”hidden” name=”notify_url” value=”#”>
<input type=”hidden” name=”return” value=”#”>
<input type=”hidden” name=”rm” value=”2″>
<input type=”hidden” name=”cbt” value=”Return to The Store”>
<input type=”hidden” name=”cancel_return” value=”#”>
<input type=”hidden” name=”lc” value=”GB”>
<input type=”hidden” name=”currency_code” value=”GBP”>
<input type=”hidden” name=”on0″ value=”CustomID”>
<input type=”hidden” name=”os0″ value=”echo $size[size]”>
<input type=”image” src=”https://www.paypal.com/en_GB/i/btn/x-click-but5.gif” name=”submit” alt=”Make payments with PayPal – its fast, free and secure!” align=”right”>
</form>’;
}
?>
thanks for any help ?