Jump to content
Killersites Forums


  • Posts

  • Joined

  • Last visited

cabey84's Achievements


Newbie (1/14)



  1. Hi there, I am trying to create a multipart form where a user logs in, then fills out their information, uploads a document, and then are led to a shopping cart. I have already created the shopping cart, but need help with the first 3 steps and how to basically link them together. Can anyone offer any books and/or tutorials that might be of assistance? Thanks so much.
  2. Problem solved. First of all, I was putting session_start() before the class definitions were uploaded on the page. Secondly, I forgot to serialize the session object after it had been stored in session and unserialized. This was a really good lesson on learning how to store PHP objects in sessions.
  3. Thanks for that suggestion. I tested the source code and I get the same error. Fatal error: Call to a member function AddItem() on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\shoppingcart2\html\addToCart.php on line 13 When I delete cookies on my browser, the source code works. Why is this happening?
  4. I am typing the code. I compared it to the source files and my code looks the same. I think it might be a problem related to serialization and storing the object in the session. From the php manual: " It is strongly recommended that you include the class definitions of all such registered objects on all of your pages, even if you do not actually use these classes on all of your pages. If you don't and an object is being unserialized without its class definition being present, it will lose its class association and become an object of class __PHP_Incomplete_Class_Name without any functions available at all"
  5. Hi there, Sorry for all the questions. I'm a newbie trying to work my way through the Killer PHP video tutorials and everything was fine until I hit the shopping cart tutorial. The approach that the video tutorial takes is to create a ShoppingCart class and then create a shoppingcart object. I am running into several problems. Step #1- Checking to see if the Session Variable is set. If it is not, then a constructor is used to instantiate an object of ShoppingCart class. If it is set, then it is to return the variable in SESSION. (This value is later serialized.) function get_shopping_cart() { if(!isset($_SESSION["cart"])) { return new ShoppingCart; } else { return unserialize($_SESSION["cart"]); } } $shopping_cart = get_shopping_cart(); Step #2: Use the methods defined in ShoppingCart class on the shopping_cart object. For example: $shopping_cart->AddItem($product_id); PROBLEM: This works just fine when SESSION['cart'] has not been set and therefore an object is created. However, I run into a problem when it is already set. I receive the error "call to a member function of a nonobject" Step #3: If Steps 1 and 2 work ok, then my next question is about the code in the tutorial for AddItem method in the ShoppingCart class. public function AddItem($product_id) { if(array_key_exists($product_id, $this->items)) { $this->items[$product_id] = $this->items[$product_id] + 1; } else { $this->items[$product_id] = 1; } PROBLEM: For some reason, after an item is added the first time around, if I hit the back button and try to add it again, the first one that I added disappears. Is it something wrong with the code or sessions? I have session_start() at the beginning of every page. I'm stumped! :/
  6. Thanks so much for your help. I actually just ended up leaving out the foreach loop altogether and stuck with using an if statement within the while loop because I need to be able to loop through all the products.
  7. Hi, I am going through the PHP Shopping Cart tutorial where xml rather than a mysql database was used to construct the data. I have been trying to adjust the code to fit with the use of the mysql database, but I keep running into some problems. The first one that has me completely stumped is checking to see if the product exists in the database. In the video tutorial, using xml, the code is as follows: function product_exists($product_id) { foreach (get_xml_catalog() as $product) { if ($product->id == $product_id) return true; } return false; } My code, to adjust for the use of a mysql database is as follows: function product_exists($product_id) { global $connection; $query = "SELECT * from products"; $result = mysql_query ($query, $connection); $product = mysql_fetch_array($result, MYSQL_ASSOC); foreach ($product as $item) { if ($product_id == $product['itemName']) { return true; } } } Since the mysql_fetch_array returns an associative array, I didnt think it would be so problematic to use a foreach loop as was done in the video tutorial. I think the main problem is that I am confused on how to use the foreach loop with regards to the mysql_fetch_array. Could someone please help?
  • Create New...