Add.php
Code: Select all
<?
include("Item.php");
$temp = new Item($_POST['sku'], $_POST['name'], $_POST['price'], $_POST['amount']);
session_start();
$count = count($_SESSION['cart']) + 1;
$_SESSION['cart'][$count] = $temp;
print_r($_SESSION['cart'][$count]);
?>Code: Select all
<?
session_start();
include("Item.php");
$_SESSION['cart'][1] = new Item(1, "Test", 10.00, 5);
$_SESSION['cart'][2] = new Item(2, "Test", 10.00, 5);
$_SESSION['cart'][3] = new Item(3, "Test", 10.00, 5);
$_SESSION['cart'][4] = new Item(4, "Test", 10.00, 5);
$_SESSION['cart'][5] = new Item(5, "Test", 10.00, 5);
$_SESSION['cart'][6] = new Item(6, "Test", 10.00, 5);
$_SESSION['cart'][7] = new Item(7, "Test", 10.00, 5);
$_SESSION['cart'][8] = new Item(8, "Test", 10.00, 5);
$_SESSION['cart'][9] = new Item(9, "Test", 10.00, 5);
$_SESSION['cart'][10] = new Item(10, "Test", 10.00, 5);
print_r($_SESSION);
$count = 1;
$total = 0;
?>
<?
while ($count <= (count($_SESSION['cart']) - 1)) {
$total += ($_SESSION['cart'][$count] -> amount * $_SESSION['cart'][$count] -> price);
echo "<tr>";
echo "\n<td width='100px'>".$_SESSION['cart'][$count] -> sku."</td>";
echo "\n<td>".$_SESSION['cart'][$count] -> name."</td>";
echo "\n<td width='100px'>".$_SESSION['cart'][$count] -> price."</td>";
echo "\n<td width='100px'>".$_SESSION['cart'][$count] -> amount."</td>";
echo "\n<td width='100px'>".'$'.$_SESSION['cart'][$count] -> amount * $_SESSION['cart'][$count] -> price."</td>";
echo "\n</tr>\n";
$count++;
}
echo "<tr><td></td><td></td><td></td><td></td><td><i><b>".'$'.$total."</b></i></td></tr>";
?>
Code: Select all
<?
class Item {
var $sku;
var $name;
var $price;
var $amount;
function __construct($skuC, $nameC, $priceC, $amountC) {
$this -> sku = $skuC;
$this -> name = $nameC;
$this -> price = $priceC;
$this -> amount = $amountC;
}
}
?>Example:
[13] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Item
[sku] => 444447896
[name] => Kendon
[price] => 30.00
[amount] => 6
)