What up...
I'm trying to build out a shopping cart that I can reuse for a few upcoming projects. I'm pretty much a newbie to php but I've been programming in other languages for a few years now. My problem is, that my objects are not being added to session. Very frustrating...
I am running PHP 4.2.3 on my shared web host. It is my understanding that objects are automatically serialized and unserialized in this version of php. Yet, for some reason my object is not being added to session.
Here is part of my code to add a product to my shopping cart for a bookstore project:
require_once('book.php');
require_once('orderlineitem.php');
require_once('order.php');
session_start();
$currentBook = new Book();
$row = $currentBook->getBookDetails($_GET['productid']);
$currentBook->setISBN($row['ISBN']);
$currentBook->setCategory($row['CategoryID']);
$currentBook->setTitle($row['Title']);
$currentBook->setAuthor($row['Author']);
$currentBook->setDescription($row['Description']);
$currentBook->setImageURL($row['imageURL']);
$currentBook->setPrice($row['Price']);
$currentOrderLineItem = new OrderLineItem($currentBook, $_GET['quantity']);
if(isset($SESSION['Order'])) {
$SESSION['Order']->addOrderLineItem($currentOrderLineItem);
echo 'Order set in session';
}
else {
echo 'Order not set in session';
$newOrder = new Order();
$SESSION['Order'] = $newOrder;
$SESSION['Order']->addOrderLineItem($currentOrderLineItem);
}
echo $_SESSION['Order']->getOrderTotal();
The weird thing is, that when it runs through the block of code above, it DOES print out the order total when I call:
echo $_SESSION['Order']->getOrderTotal();
However, on this page, I have a link <a href="test2.php">Test 2</a> to another page that calls my object to see if its in session. Here is the code on that page:
Test2.php
require_once('book.php');
require_once('orderlineitem.php');
require_once('order.php');
echo $_SESSION['Order']->getOrderTotal();
It gives me this error:
Fatal error: Call to a member function on a non-object in /test2.php on line 13
I'd appreciate any advice you guys can offer. This is pretty frustrating... Thanks in advance!