Connie Goss;10932581 wrote:
<?php
class Cart {}
{
// Create an array for holding the shopping cart contents
private $_contents = array();
// Add a product to the shopping cart
public function addProduct($proofno,$descript,$qty) {
// is proof already in cart? add if not
if (isset($this->contents[$proofno.$descript])) {
$this->contents[$proofno.$descript,2] += $qty ; // increase the quantity if it's already in cart
} else {
$this->_contents[$proofno.$descript] = array( $proof,$descript,$qty ); add image + size to cart if new
}
}
}
?>
try this
class Cart
{
// Create an array for holding the shopping cart contents
private $_contents = array();
// Add a product to the shopping cart
public function addProduct($proofno,$descript,$qty) {
// is proof already in cart? add if not
if (isset($this->_contents[$proofno.$descript])) {
$this->_contents[$proofno.$descript] += $qty ; // increase the quantity if it's already in cart
} else {
$this->_contents[$proofno.$descript] = array( $proofno,$descript,$qty ); //add image + size to cart if new
}
}
}
Your class definition was not within the parentheses
class Cart {} //<-- the problem
{
// Create an array for holding the shopping cart contents
private $_contents = array();
//etc etc etc
}
class Cart
{
// Create an array for holding the shopping cart contents
private $_contents = array();
//etc etc etc
}
and another problem in the code:
if (isset($this->_contents[$proofno.$descript])) {
$this->_contents[$proofno.$descript,2] += $qty ; //[$proofno.$descript,2] invalid
}
If your trying to access index '2' of [$proofno.$descript] array, then try this
if (isset($this->_contents[$proofno.$descript])) {
$this->_contents[$proofno.$descript][2] += $qty ;
}
Hope this helps.