x_maras Posted March 16, 2009 Share Posted March 16, 2009 I am a bit confused. I doing a small project which is a vending machine. I tried alot of things but couldnt make it work proper. The code below shows kind of what I want to do, and I will explain also <?php //error_reporting(0); include("view.php"); //session_start(); $view=new View(); ////////--------first html part----------/////////// $view->firstPart(); ////////----------------------------------/////////// //creating drinks and money forms $view->createDrinksForm(); //When I choose a drink and press the button select drink i want some details to be shown $id = $_POST['press']; echo $view->getMachine()->getDrinks($id)->getName(); $view->createMoneyForm(); $money = $_POST['money']; echo $view->getMachine()->getDrinks($id)->getPrice()."<br />"; echo $money."<br />"; ////////--------last html part----------/////////// $view->lastPart(); ////////----------------------------------/////////// ?> in the view class there is the html code in functions and there is also connection with the machine class, which is also connected with the drink class and the db class. ( if someone wants to post all the code tell me but I thought it would be too much for the post and the other classes are ok ). The problem is in the presentation. I create a radio buttons form with the drinks and a submit button. When the submit button is pressed it posts a number (the numbers are the id from the database ) and shows the name. In the second form, also with radio buttons when I press the key it should be showing the price of the drink and taking the amount of money from the post and using it in some function that they are on the machine class. The problem is that i lose the object. I tried with the serialize and the SESSION, it solved it kind of but every time tha I press a submit button creates a new object drink and doesn't keep the values of it's properties. I hope you got an idea! if not then only god can help me Sorry the size of the post and also for my english. Link to comment https://forums.phpfreaks.com/topic/149672-lost-in-serialize-and-session/ Share on other sites More sharing options...
rhodesa Posted March 16, 2009 Share Posted March 16, 2009 if you are storing objects into SESSION variables, all of the classes needed to be declared BEFORE session_start(). So on the page that is reading that back out of sessions, the order should be: 1) Inlcude all classes 2) session_start() 3) Use session variables Link to comment https://forums.phpfreaks.com/topic/149672-lost-in-serialize-and-session/#findComment-785929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.