debmc99 Posted July 18, 2010 Report Share Posted July 18, 2010 Hi. I hope I am in the right forum. Sorry if these are dumb questions but I am a beginner. I purchased the PHP Shopping Cart video tutorial, I have wamp and eclipse installed. Everything was going fine up until video #7 - Building the Shopping Cart Object. I am typing the code along with the video. But when it is time to test it I keep getting errors like this: Fatal error: Call to a member function EmptyCart() on a non-object Eclipse is not showing any errors. I have typed everything exactly. When I look at the source file in Firefox I see this: EmptyCart(); echo render_notification('Shopping Cart Emptied'); } set_shopping_cart($shopping_cart); ?> Any advice would be appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 18, 2010 Report Share Posted July 18, 2010 The PHP error should indicate the file name/line number where the error is occurring. Perhaps you can post the code from that file? (the code from the entire file, not just the line with the error) I realize you say that "you have typed everything exactly" but it's probably due to a typo of some sort. Quote Link to comment Share on other sites More sharing options...
debmc99 Posted July 19, 2010 Author Report Share Posted July 19, 2010 Here is the exact error message: Fatal error: Call to a member function AddItem() on a non-object in C:\wamp\www\my_php\shoppingcart\PaypalShoppingCart\html\addToCart.php on line 14 Line 14 is this: $shopping_cart->AddItem($product_id); Here is the code: <?php require_once '../functions/functions.php'; $shopping_cart = get_shopping_cart(); ?> <?php echo render_header('Pasta Shop: Catalog');?> <?php $product_id= $_REQUEST['id']; if (product_exists($product_id)) { $shopping_cart->AddItem($product_id); } ?> <?php function render_shopping_cart_row(ShoppingCart $shopping_cart , $product_id , $line_item_counter) { $quantity = $shopping_cart->GetItemQuantity($product_id); $output = " <tr> <th> $product_id </th> <th> $quantity </th> <th> $ Amount </th> </tr> "; return $output; } ?> <table class='shoppingCart'> <?php $line_item_counter = 1; foreach ($shopping_cart->GetItems() as $product_id) { echo render_shopping_cart_row($shopping_cart , $product_id , $line_item_counter); $line_item_counter ++; } ?> <tr> <td> product_id </td> <td> quantity </td> <td> $amount </td> </tr> </table> <?php set_shopping_cart($shopping_cart); ?> <?php echo render_footer();?> Thank you for your help. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted July 19, 2010 Report Share Posted July 19, 2010 I don't think there's anything wrong with the code you posted above... no typos or errors that I can see. It's possible the error doesn't have anything to do with this file itself, and maybe the get_shopping_cart() function is wrong somehow. If that function isn't getting the shopping cart correctly, I imagine the addItem() function will throw an error. Perhaps you can post the code to that function? It may be better to simply send me all the files (compress them into one ZIP file, if you can) and I can take a look directly -- ben [at] falkencreative.com. It's a bit hard to figure this out when you're dealing with multiple files and functions all calling each other. Quote Link to comment Share on other sites More sharing options...
debmc99 Posted July 19, 2010 Author Report Share Posted July 19, 2010 Thanks Ben, There was a problem with the get_shopping_cart() function. It is working at the moment. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.