I am using sessions to pass the main object from one page to another in a shopping cart script. The main object is $cart
Here is some code:
?
session_start();
session_register('cart');
include("cart_class.php");
include("db.php");
if (!is_object($cart)) {
$cart = new Cart;
$test = "yadda yadda";
}
if (!$func) {
// Get all items from the database and put into an Array
$query = "SELECT id, pName FROM hal_item";
$qresult = mysql_db_query($database, $query, $connection) or die ("Error in query: $query . " . mysql_error());
while($row = mysql_fetch_row($qresult)) {
$id = $row[0];
$pname = $row[1];
$products_arr[$id] = $pname;
}
// Show all Items
foreach ($products_arr as $id => $product) {
$url_product = urlencode($product);
echo "Product: <a href='$PHP_SELF?sid=$SID&func=add&id=$id&product=$url_product'>$product</a><br>\n";
}
echo $cart;
}
if ($func == 'add') {
// Add function
// add("ID", NUM);
// Adds NUM to cart for ID
$result = $cart->add("$id", "$product", 1);
echo $result;
}
When I try this it gives me this error:
Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition cart of the object you are trying to operate on was loaded before the session was started in /xxx/xxxx/products.php on line 43
Does anyone know why it is doing this? Is it possible to pass objects through sessions? And if i do it like this, will each user that creates a new $cart object have a unique cart?