Pavlos1316 Posted May 9, 2011 Share Posted May 9, 2011 Hello (I am posting to php because I don't know what is giving the problem), Let's say I have these links into my <div id="header>: Home Items Faq Cart and I use a Jquery to open my links inside my <div id="content"> The problem is between Items and Cart links (I am testing in ie9 and firefox 4): I am using an ajax code (I don't know if the problem is in here) to add items to cart and stay at my items page (not sending me to the cart page). Now, when I first load the page or is refreshed, everything works fine. BUT after I add something to the Cart if I visit the Cart.php and then return to my Items.php, when I click on the next item to be added I get a Blank page. Note: the Item is added normaly. This is happening also, when I click the UPDATE button inside my cart php to update quantities. Any suggestion? Thank you. (I don't know if is ajax, php, jquery or all three of them) Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/ Share on other sites More sharing options...
Pavlos1316 Posted May 10, 2011 Author Share Posted May 10, 2011 Anyone Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1213289 Share on other sites More sharing options...
Maq Posted May 10, 2011 Share Posted May 10, 2011 Without seeing relevant code it's impossible to tell exactly what it is. PHP will cause a blank page if there is a fatal error. You can temporarily turn on max error reporting by placing these 2 lines directly below your opening <?php tags: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1213372 Share on other sites More sharing options...
Pavlos1316 Posted May 11, 2011 Author Share Posted May 11, 2011 Correct... (but at first I didn't know what to post) I will post my page with the items... As for the 2 line code, I've tried it... I got no errors.... I will give it a go again... Here's my code: <script type="text/javascript"> $(document).ready(function() { $().ajaxStart(function() { $('#loading').show(); $('#result').hide(); }).ajaxStop(function() { $('#loading').hide(); $('#result').fadeIn('slow'); }); $('.itmform').submit(function() { $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), success: function(data) { $('#result').html(data); } }) return false; }); }); </script> </head> <body> <p class="difftext">...body</p> <br /> <br /> <table width="95%" align="center"> <tr> <td width="10%"><img src="../pfolder/wb0001.png" height="105px" width="100px"> </td> <td width="35%"> <form name="form1" id="form1" class="itmform" method="post" action="cart-add.php?action=add&id=1"> <span class=itmttl>blablabla</span> <br /> <span class=text>blablabla. <br /> blablabla.</span> <br /> <input type="submit" name="submit" value="Add to cart" /> </form> <br /> <br /> <form name="form2" id="form2" class="itmform" method="post" action="cart-add.php?action=add&id=2"> <span class=itmttl>blablabla</span> <br /> <span class=text>blablabla</span> <br /> <input type="submit" name="submit" value="Add to cart" /> </form> </td> </tr> </table> and the code that handles the ADD action: <?php // Include MySQL class require_once('sql.php'); // Include database connection require_once('xxxconn.php'); // Include functions require_once('function.php'); session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?> Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1213665 Share on other sites More sharing options...
Pavlos1316 Posted May 12, 2011 Author Share Posted May 12, 2011 So any ideas Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1214311 Share on other sites More sharing options...
Maq Posted May 12, 2011 Share Posted May 12, 2011 I don't see where you tried my suggestion... Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1214489 Share on other sites More sharing options...
Pavlos1316 Posted May 13, 2011 Author Share Posted May 13, 2011 Me the j@@@@@ss.... I had paste the code in the wrong file, I did it now and this is the mistake that it gives (for my add item code): PHP Notice: Undefined index: cart in /home/sonophoe/public_html/marykaycyprus.com/additm.php on line 13 and my line 13 in there is: $cart = $_SESSION['cart']; I don't know what it means but I will tell you that: My add item code "additm.php" was included inside my cart.php. I removed it and created 2 separate files. Did I do wrong? Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1214904 Share on other sites More sharing options...
Maq Posted May 13, 2011 Share Posted May 13, 2011 It means you didn't set 'cart' in the SESSION array before using it here. Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1214975 Share on other sites More sharing options...
Pavlos1316 Posted May 14, 2011 Author Share Posted May 14, 2011 How should I set it...??? Sould I use something like: if(isset($_SESSION["cart"])) { $cart = $_SESSION["cart"]; } Thank you Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215381 Share on other sites More sharing options...
Pavlos1316 Posted May 14, 2011 Author Share Posted May 14, 2011 Okkk... I HAVE NO IDEA IS HAPPENING... I don't get the error now, even if I have the code as I first posted it, BUT the blank page is still there...! How is this possible???? If the page is refreshed or 1st opened, you can add as many items inside the cart, without any problem. But IF you visit ANY other link in the page once and then go back to the items and hit ADD... BOOM here's the blank page!!!! Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215398 Share on other sites More sharing options...
anupamsaha Posted May 14, 2011 Share Posted May 14, 2011 Put session_start() at the top (below <?php) tag and see how it works. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215483 Share on other sites More sharing options...
Pavlos1316 Posted May 14, 2011 Author Share Posted May 14, 2011 I did...I have session_start in my pages. ie gives me no error, ff gives me the error.... I am 100% confused.... Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215493 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 14, 2011 Share Posted May 14, 2011 How should I set it...??? Sould I use something like: if(isset($_SESSION["cart"])) { $cart = $_SESSION["cart"]; } Thank you What is the purpose of your $_SESSION['cart'] variable? What data should it be holding? Should it be holding all of the items added to the cart? Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215496 Share on other sites More sharing options...
Pavlos1316 Posted May 14, 2011 Author Share Posted May 14, 2011 yes.... all of the items that are added--removed--updated to the cart. Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215497 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 14, 2011 Share Posted May 14, 2011 If you're setting the $_SESSION['cart'] variable with that information, then you shouldn't be getting an error saying that it isn't set. Can we see the code that sets that information into the $_SESSION['cart'] variable? From the code you posted, I don't see that information being placed in the variable. Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215498 Share on other sites More sharing options...
Pavlos1316 Posted May 14, 2011 Author Share Posted May 14, 2011 The only thing I have is this $_SESSION['cart'] = $cart; at the end of the code I posted... Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215507 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 15, 2011 Share Posted May 15, 2011 Alright, the only thing I can think of is concatenate the $cart variable at the beginning of the script and see what happens. $cart .= $_SESSION['cart']; It seems like since you're getting session data into $cart, basically after looping through each time, it's overwriting stuff. Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1215639 Share on other sites More sharing options...
Pavlos1316 Posted May 18, 2011 Author Share Posted May 18, 2011 IF: $cart = $_SESSION['cart']; Undefined index: ..... for the above(line13) IF: $cart .= $_SESSION['cart']; Undefined variable: ..... for the above (line13) and Undefined index: ..... line 14 which is: $action = $_GET['action']; Quote Link to comment https://forums.phpfreaks.com/topic/235899-blank-page-out-of-nowhere/#findComment-1217016 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.