New $_SESSION data causing a glitch in removing action?
Posted: Sat Jan 29, 2011 5:30 pm
This is a little difficult to explain but hopefully someone here can point me to specific phrases that can help me figure out this problem.
The Problem:
When I remove an item from my shopping cart, the following code still shows up as the price information even though I wanted the item completely gone:
The Chain of Events:
When I remove an item, I press the following remove items button:
which calls the remove action outlined below:
you'll notice the eight unset lines below. That's because I suspect it's by adding values to the $_SESSION data that caused the removal of items to function incorrectly. The adding of $_SESSION values can be seen below.
The $g value counts how many packages total appear on the page, and $i counts how many items are on the page.
When I output an array onto the page that lists all the item data available, it says two items remain in the page and echoes their values.
THE QUESTIONS:
1. Did adding values to the $_SESSION data cause this incomplete deleting of items from the shopping cart?
2. Why does that price-related chunk of code remain but the rest disappears from view? The error also offsets the count of $g and $i.
3. If #1 is true, then is my unset code correct?
4. If #2 is not true, then is it something else in the code?
I appreciate the time it took you to read this and look forward to hearing any and all suggestions or solutions you have.
The Problem:
When I remove an item from my shopping cart, the following code still shows up as the price information even though I wanted the item completely gone:
Code: Select all
<span class="style1">Price:</span> $
<?
if($line['ceiling']=='Y' && $line['static']=='N'){
$query = "SELECT * from ceiling where deleted=0 and pid=" . $items[0];
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$ceil_cost = mysql_fetch_array($result, MYSQL_ASSOC);
$line['price']=$ceil_cost['h' . $ceiling[0]];
mysql_free_result($result);
}
echo number_format($line['price'],2);
?>
Select one of the following options to modify this item<br />
<br />When I remove an item, I press the following remove items button:
Code: Select all
<? echo '<a class="sub" href="viewcart5.php?back=' . urlencode($_GET['back']) . '&action=rem&id=' . $i . '"><img src="https://www.jezebelgallery.com/images/topbuttons/removefromcart.gif" alt="Remove" /></a> '; ?><br />
<? Code: Select all
for($i=0;$i<sizeof($_SESSION['cart']);$i++){
if(($_GET['action']=='rem'||$_GET['action']=='rev') && $_GET['id']==$i){
if($_GET['action']=='rev'){
$val=$_SESSION['cart'][$i];
$items= split("\|\|",$val);
}
$_SESSION['cart'][$i]="";
if($_GET['action']=='rev'){
header("Location: pro.php?id=" . $items[0]);
exit;
}
}
$val=$_SESSION['cart'][$i];
$items= split("\|\|",$val);
if($items[0]!=""){
$num_items++;
unset($_SESSION['shiplength'][$i]);
unset($_SESSION['shipwidth'][$i]);
unset($_SESSION['shipheight'][$i]);
unset($_SESSION['shipweight'][$i]);
unset($_SESSION['shiplength2'][$i]);
unset($_SESSION['shipwidth2'][$i]);
unset($_SESSION['shipheight2'][$i]);
unset($_SESSION['shipweight2'][$i]);
}
}Code: Select all
if (is_numeric(substr($itemshippinginfo[0]['length'],0,1)));{
$_SESSION['shiplength'][$g]=$itemshippinginfo[0]['length'];
$_SESSION['shipwidth'][$g]=$itemshippinginfo[0]['width'];
$_SESSION['shipheight'][$g]=$itemshippinginfo[0]['height'];
$_SESSION['shipweight'][$g]=$itemshippinginfo[0]['weight'];
if (strlen($itemshippinginfo[2]['length'])>0) {
$g++;
$_SESSION['shiplength'][$g]=$itemshippinginfo[2]['length'];
$_SESSION['shipwidth'][$g]=$itemshippinginfo[2]['width'];
$_SESSION['shipheight'][$g]=$itemshippinginfo[2]['height'];
$_SESSION['shipweight'][$g]=$itemshippinginfo[2]['weight'];
}
}
}
}When I output an array onto the page that lists all the item data available, it says two items remain in the page and echoes their values.
THE QUESTIONS:
1. Did adding values to the $_SESSION data cause this incomplete deleting of items from the shopping cart?
2. Why does that price-related chunk of code remain but the rest disappears from view? The error also offsets the count of $g and $i.
3. If #1 is true, then is my unset code correct?
4. If #2 is not true, then is it something else in the code?
I appreciate the time it took you to read this and look forward to hearing any and all suggestions or solutions you have.