A: 

You need to

include_once("ShoppingCart.php");

Read up on the different ways to include files

http://www.w3schools.com/PHP/php_includes.asp

Byron Whitlock
+1  A: 

You probably need to include the ShoppingCart.php file in your main page, so it has the definition of the ShoppingCart class. Try putting at the top of your main page:

<?php require('ShoppingCart.php'); ?>

What I think might be happening is that the cart object is getting unserialised from the Session, but there is no class definition, so it becomes an instance of an incomplete class. When you then call a method on it you are getting a fatal error. What probably doesn't help is that you may not be displaying errors, so the script will just end. You could also try putting at the top of the main page:

<?php ini_set('display_errors', true); ?>

This should make PHP errors get shown.

Edit

It might be worth pointing out that you can't store a database connection in the session. You need to connect to the server / select the database etc. on every request. I don't think your script is currently doing that.

Also, you can store objects in the session without worrying about the serialisation yourself, here is a quick example:

<?php
//include class definition before starting session.
require('ShoppingCart.php');

session_start();

if (!isset($session['cart'])) {
    $session['cart'] = new ShoppingCart();
}

$cart = $session['cart'];

//do stuff to cart
$cart->doSomething();

//changes are now saved back to the session when the script is terminated, without you having to do anything.
Tom Haigh
Good call on the deserialization.
Byron Whitlock
OOPS I thought I copied the entire code from the main page. I do have the require code added. This is what I have before the code I already posted:<?php require_once("shoppingCart.php"); session_start(); $_SESSION['curCart'];?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict-dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Cart Connection</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head>...