<?php
ob_start();
session_start();


echo $_POST['price'];
echo "<br />";
echo $_POST['prodid'];
echo "<br />";
echo $_POST['weight']; 
echo "<br />";
echo $_POST['qty']; 
echo "<br />";
echo $_POST['pname']; 
echo "<br />";
echo $_POST['color']; 
//exit;

   if($_GET['row']!="")
	{
	 $p=$_SESSION['idlcount'];
	
	    for($j=1;$j<=$p;$j++)
	     {
	       if($_SESSION['idlcart'][$j]['prodid']==$_GET['row'])
		    {
			unset($_SESSION['idlcart'][$j]);
			$deleting=1;
			$_SESSION['idlcount']=$_SESSION['idlcount']-1;
		   }
		   if($deleting==1)
		   {
			   $_SESSION['idlcart'][$j]=$_SESSION['idlcart'][$j+1];
		   }
	    }
		 
	}

        if($_POST['hidval']=="updatenow")
		{   
		
		     for($i=1;$i<=$_SESSION['idlcount'];$i++)
			 {
				
				
			    $_SESSION['idlcart'][$i]['qty']=$_POST[$i]; 
			    $_SESSION['idlcart'][$i]['totprice']=$_SESSION['idlcart'][$i]['price']*$_SESSION['idlcart'][$i]['qty'];
				$_SESSION['idlcart'][$i]['totwieght']=$_SESSION['idlcart'][$i]['weight']*$_SESSION['idlcart'][$i]['qty'];
			 //echo $_SESSION['idlcart'][$i]['totprice']; 
			 }
			 
		 }


if(isset($_POST['qty']))
{   
	if($_SESSION['idlcount']==0 || isset($_SESSION['idlcount']))
	{ 
		$_SESSION['idlcount']=$_SESSION['idlcount']+1;
		$k=$_SESSION['idlcount'];
		
	}
	else
	{
		$_SESSION['idlcount']=1;
		$k=$_SESSION['idlcount'];
	}

        
		if(isset($_SESSION['idlcart']))
           { 
			   $idlcounts=0;
			    foreach($_SESSION['idlcart'] as $cartitems)
			      {
			             
					if($cartitems['prodid']==$_POST['prodid'] )
					{
						  $productrepeat=$cartitems['prodid'];
						
		  $error="error";
		  $_SESSION['idlcount']=$_SESSION['idlcount']-1;
		 $k= $_SESSION['idlcount']; 
		 $idlcounts=1; 
		break;
					}
				  }
			  
			   if($idlcounts==0)
			       { 
				  $_SESSION['idlcart'][$k]=array("qty"   =>  $_POST['qty'],
										"price"  => $_POST['price'],									
										"prodid"  => $_POST['prodid'],
										"pname"  => $_POST['pname'],
										"color" => $_POST['color'],
										"weight"=> $_POST['weight'],
										"totwieght"=>$_POST['qty']*$_POST['weight'],
										"totprice"=> $_POST['qty']*$_POST['price'] ); 
			        }
			  
		  }
	     else
		  { 
			$_SESSION['idlcart'][$k]=array("qty" =>  $_POST['qty'],
										   "price"  => $_POST['price'],
										   "prodid"  => $_POST['prodid'],
										   "pname"  => $_POST['pname'],
										   "color" => $_POST['color'],
										   "totprice"=> $_POST['qty']*$_POST['price'],
										   "weight"=> $_POST['weight'],
										   "totwieght"=>$_POST['qty']*$_POST['weight']);
									     
										
										
		}
}
 print_r($_SESSION['idlcart']); 
 $k=$_SESSION['idlcount'];  
 for($i=1;$i<=$k;$i++)
 { 
	 $_SESSION['totalquentity']=$totqty=$totqty+$_SESSION['idlcart'][$i]["qty"];
	 $_SESSION['totalamount'] =$totres=$totres+$_SESSION['idlcart'][$i]["price"];

 } 
 if($error=="error")

 { 
 header("location:cart.php?prodid=".$cartitems['prodid']."&error=yes");
 }
	else
	{
	header("location:cart.php"); 
	}
?>