Jump to content

Blank page out of nowhere


Pavlos1316

Recommended Posts

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)  :confused:

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Okkk... I HAVE NO IDEA  :wtf: 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!!!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.