error in class
Posted: Tue Mar 20, 2007 8:19 am
Code: Select all
<?php
mysql_connect ("localhost", "root", "") or die (mysql_error());
mysql_select_db ("redsquare") or die (mysql_error());
class cart
{
function cart () {
@session_start ();
// check to see if anything needs adding or removing from the cart
$this = $this->loadCart (session_id());
if ($this == FALSE) {
unset ($this);
}
if (isset($_POST['cartAction'])) {
$this->actionRequired ();
}
}
function add ($productStockCode, $size, $quantity) {
$duplicate = FALSE;
// it possible for someone to add a duplicate item to the system instead of it being
// labelled as 2 quantity, we'll check this here and if applicable, alter the quantity
if (isset($this->cart['contents'])) {
for ($i = 0; $i < count ($this->cart['contents']); $i++) {
if (($this->cart['contents'][$i]['productStockCode'] == $productStockCode) && ($this->cart['contents'][$i]['productSize'] == $size)) {
$this->cart['contents'][$i]['productQuantity'] = ($this->cart['contents'][$i]['productQuantity'] + $quantity);
$duplicate = TRUE;
}
}
}
if ($duplicate === FALSE) {
$this->cart['contents'][] = $this->getItemDetails ($productStockCode, $size, $quantity);
}
$this->update ();
}
}
#<!---------------------Usage Example WITHOUT cart ---------------------------!>
$cart = new cart ();
#$cart->add (72490, 'Lge', 3); // add 1 x productCode 72597
#$cart->add (71815, 'Med', 1); // add 1 x productCode 72400
#$cart->add (72583, '32', 1); // add 1 x productCode 72400
#$cart-> saveCart();
#print_r ($cart);
?>Code: Select all
Fatal error: Call to a member function on a non-object in C:\netserver\www\classes\cart\cart.class.php on line 15edit: notice the auto call for the class at the end of the script, it also only happens when $_POST['cartAction'] is set, obviously.