Page 1 of 1

Storing an object as a session variable.

Posted: Fri Aug 05, 2005 2:00 pm
by Luke
Hello, I am new to this forum, sorry to make this my first post... I will be helpful... I promise. Anyway, here's my problem. I am making a program where my town's chamber of commerce can log in, add, delete, and edit posts of events on their website. All was going fine until I tried to store an object in a session and then use it later on. Here's the script:

Code: Select all

include_once(".../includes/basicfunctions.php");
include_once(".../includes/sessionfunctions.php");
include_once(".../includes/validationclasses.php");

if($_POST['action'] == "preview"){
    $event = new event($_POST);
    if($preview = $event->view()){
        session_register('post');
        $_SESSION['post'] = $event;
        $msg = "Submit Post?";
        $preview = urlencode($preview);
    }
    else{
        $msg = "Could not post. Please contact administrator.";
        logerror("Could not preview post. event->preview()");
    }
}
else{
    $event = $_SESSION['post'];
    if($event->post()){
        $msg = "Post successful";
    }
    else{
        $msg = "Could not post. Please contact administrator. ";
        logerror("Could not post. event->post()");
    }
}
header("Location: $rootdir/edit/calendarevents.php?msg=$msg&preview=$preview");
and here is the error I am getting...

Code: Select all

Fatal error: main() [function.main]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "event" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in c:\wamp\www\postprogram\forms\postcalendar.php on line 21
Does anybody know how I can store an object in a session and use it later?


feyd | please use

Code: Select all

tags when posting php code.[/color]

Posted: Fri Aug 05, 2005 2:30 pm
by feyd
include the class definition before you call session_start()

Posted: Fri Aug 05, 2005 2:47 pm
by Luke
Wow... that was too easy. Thank you very much.... all I had to do was switch the two includes on the top.