Page 1 of 1

loop when add to cart is clicked

Posted: Thu Dec 29, 2011 1:36 pm
by louiejin
may i ask what will i do so that, if i add to cart the $val=$_get['val'] will not ask again wen it will loop back again to the product page

this are the structure of my code:


my index the color red text of my add to cart case the blue is my product case

Code: Select all

<link rel="stylesheet" href="view/shop/style2.css" type="text/css" />
<? include("dbconnect.inc"); #includes db connection ?>
<? include("functions.php"); #includes the db function ?>
<? include("cart_functon.php"); #includes the cart function ?>
<body>
<?
	#set up default cart values
	if(!isset($_SESSION['cart']))
	{
		#@$_SESSION['cart'] = array();
		@$_SESSION['total_items'] = '0';
		@$_SESSION['total_price'] = '0.00';
	}

	#if view if empty it goes to index and if not it goes to the choosen view
	$view = empty($_GET['view']) ? 'index' : $_GET['view'];

	$controler = 'shop'; #used to view the shop

	#checks w/c view s requested
	switch($view)
	{
		case "index":
		
		break;
		
		case "termsandcondition":
		
		break;

		case "aboutus":
		
		break;

		case "forums":
		
		break;
		
		case "processlogin":
		
		break;
		
		case "destroy":
		
		break;
		
		case "registrationfrom":
		
		break;

		[color=#000080]case "products":
		
			$product = find_products();
			
			$val =$_GET['val'];[/color]
		
		break;
		
		case "user":
		
		break;
		
		case "transhistory":
		
		break;
		
		case "orderperday":
		
		break;
		
		case "orderingsatatus":
		
		break;
		
		case "forumsstatus":
		
		break;
		
		case "addproduct":
		
		break;
		
		case "delproduct":
		
		break;
		
		case "addprocess":
		
		break;
		
		case "mycomments":
		
		break;
		
		case "myaccounts":
		
		break;
		
		case "mypoints":
		
		break;
		
		case "myorders":
		
		break;
		
[color=#FF0000]		case "add_to_cart":
		
			
			$id = $_GET['id'];
			$add_items = add_to_cart($id);
			$_SESSION['total_items'] = total_items($_SESSION['cart']);
			$_SESSION['total_price'] = total_price($_SESSION['cart']);
			header('location: index.php?view=products');[/color]
		break;
		
		case "update_cart":
			update_cart();
			$_SESSION['total_items'] = total_items($_SESSION['cart']);
			$_SESSION['total_price'] = total_price($_SESSION['cart']);
			header('location: index.php?view=viewcart');
		
		break;
		
		case "viewcart":
		
		break;
		
	}
	
	include($_SERVER['DOCUMENT_ROOT'].'/'.'for_se_only/view/'.$controler.'.php');/*includes the controler value w/c is the shop with the file type .php*/

?>


the module wer will i can get the value for $val = $_get['val'] wen i dint use the add to cart
		
		        <li><a href="#" class="withsub" tabindex="1">Mens Apparel</a><img src="img/up.gif" alt="" />
			<ul>
		<?
			$query_mens = "select * from category where type_id = 1";
			$mens_res = mysql_query($query_mens);
			
			while($row_mens = mysql_fetch_array($mens_res))
			{
				extract($row_mens);
			
			
		?>
				<li><a href="index.php?view=products&val='<? echo $cat_id ?>'"><? echo $cat_name; ?></a></li>
		<?
			}
		?>
				
			</ul>
		</li>
        <li><a href="#" class="withsub" tabindex="1">Womens Apparel</a><img src="img/up.gif" alt="" />
			<ul>
		<?
			$query_mens = "select * from category where type_id = 2";
			$mens_res = mysql_query($query_mens);
			
			while($row_mens = mysql_fetch_array($mens_res))
			{
				extract($row_mens);
			
			
		?>
				<li><a href="index.php?view=products&val='<? echo $cat_id ?>'"><? echo $cat_name; ?></a></li>
		<?
			}
		?>
			</ul>
		</li> 
        	
		        <li><a href="#" class="withsub" tabindex="1">Kids</a><img src="img/up.gif" alt="" />
			<ul>
		<?
			$query_mens = "select * from category where type_id = 3";
			$mens_res = mysql_query($query_mens);
			
			while($row_mens = mysql_fetch_array($mens_res))
			{
				extract($row_mens);
			
			
		?>
				<li><a href="index.php?view=products&val='<? echo $cat_id ?>'"><? echo $cat_name; ?></a></li>
		<?
			}
		?>
			</ul>
		</li> 
		
        		<?
			$query_mens = "select * from category where type_id = 4";
			$mens_res = mysql_query($query_mens);
			
			while($row_mens = mysql_fetch_array($mens_res))
			{
				extract($row_mens);
			
			
		?>
				<li><a href="index.php?view=products&val='<? echo $cat_id ?>'"><? echo $cat_name; ?></a></li>
		<?
			}
		?> 
		<?
			$query_mens = "select * from category where type_id = 5";
			$mens_res = mysql_query($query_mens);
			
			while($row_mens = mysql_fetch_array($mens_res))
			{
				extract($row_mens);
			
			
		?>
				<li><a href="index.php?view=products&val='<? echo $cat_id ?>'"><? echo $cat_name; ?></a></li>
		<?
			}
		?>