ero100 0 Newbie Poster

I want to add SIZING OPTIONS to my website

* i have created the database sizes with: size_id, size_list, and prod_id which is the ID OF the products tables as foreign key

* i have issued a query to retrieve all the sizes according to the prod_id (product ID). as HTML select list of value.

Problem

* it retrieve the sizes related to the product from the database, but when i select one size, it add to the cart only one size which is (the first on the list), and even if i choose different size it will always add the same size never the other one i have selected.
basicaly the problem is that its is not passing the size that i select to the shopping cart.

would you have a look at this script and help me to understand where is the mistake is, or give me an idea about what type of changes should i do in the script in order to get the results i want?

thanks everyone for the help given.

bellow is the code of the two pages

--> products.php
--> cart2.php


PRODUCTS.PHP

<div class="main_wrap">
<div class="main_content">
<?php

if ((isset($_GET['cat_id']))and(isset($_GET['sub_cat_id'])))

{	
    $cat_id = $_GET['cat_id'];
	$sub_cat_id = $_GET['sub_cat_id'];
	
	$cat_query = mysql_query("SELECT * FROM categories WHERE cat_id=$cat_id",$con);

//Loop the result of Categories

if($cat_row = mysql_fetch_array($cat_query))
{
	    $cat_name = $cat_row['cat_name'];
        

// start sub_category query

$sub_cat_query = mysql_query("SELECT * FROM sub_categories WHERE sub_cat_id=$sub_cat_id",$con);
	
	   if ($sub_cat_row = mysql_fetch_array($sub_cat_query))
	    { 
	         //Find out the name of the sub category
	         $sub_cat_name = "".$sub_cat_row['sub_cat_name'];

		//As long there is subcategories loop the results as bellow	
			echo $cat_name;
			echo " --> ";
			echo $sub_cat_name;
			
			echo "<br/>";
			echo "<br/>";

	    }

 }

}

//start display products list

$product_query = mysql_query("SELECT * FROM products WHERE cat_id=$cat_id and sub_cat_id=$sub_cat_id",$con);

while($prod_row = mysql_fetch_array($product_query))
	{	
	
	$sub_cat_id = $sub_cat_id['sub_cat_id'];
	$prod_id = $prod_row['prod_id'];

// query size from sizes table

echo "<form method= \"post\" action = \"cart2.php\">

<div class='item_pic_box'>

<div class='item_name_box'><b>".$prod_row['prod_name']."</b></br></a></div>
<div class='item_price_box'>Pre&ccedil;o: &pound;".$prod_row['prod_price']."


<div class='select_size'>"; 

if ($prod_row['prod_stock']>0)
{
echo "<select name='size_list'>";

$size_query = mysql_query("SELECT size_list FROM sizes where prod_id=$prod_id",$con);
  
  while ($size_row = mysql_fetch_array($size_query))
	
	{	
	$size_list = $size_row['size_list'];
	
echo "<option value='size_list'>$size_list</option>";

}

echo "</option>";
echo "</select>";

}else  

echo "";


/* out of stock lines */

if ($prod_row['prod_stock']>0)

     echo "<div class='item_cart_bt_box'><a href='cart2.php?action=add&prod_id=$prod_id'><img src='../images/shopping_cart.png'></a></div>"; //item_price_box
 else 
	echo "<div class='item_out_stock_box'>Estoque Vendido</div>";

echo "</div>";

echo "</div>";
echo "</div>";

	}

echo "</form>";

?>

CART2.PHP

<div class="main_wrap">
<div class="main_content">

<?php

// start cart updating script

if (isset($_GET['prod_id'])){
	$prod_id = $_GET['prod_id'];

}else 
	
	$prod_id = 1;
	
	//echo $prod_id; 						// echo to check if the product_id has been SET, if displayed means, its SET.
	
if (isset($_GET['action']))
	$action = $_GET['action'];
else
	$action = "$empty";
	
switch($action)
{
case "add":

	if ($_SESSION['cart'][$prod_id])    // if already has a product with same ID (prod_id)
		$_SESSION['cart'][$prod_id]++;  // increment it by 1
	else								// otherwise
		$_SESSION['cart']=1;			// set it as first value, which mean, = to 1.
		
	break;
	
case "remove":

	if ($_SESSION['cart'][$prod_id])  
	
	{
		$_SESSION['cart'][$prod_id]--; 
	if ($_SESSION['cart'][$prod_id] == 0)
		unset($_SESSION['cart'][$prod_id]);
	}
	break;
	
case "empty":

unset($_SESSION['cart'][$prod_id]);
	break;
	
}

// finish cart updating script


//start DISPLAY CART SCRIPT

if (isset($_SESSION['cart']))
  {
  

  
echo "<form id='form1' name='form1' method='post' action='checkout.php'>";  
echo "<table border=1 cellspacing=1 cellpadding=0 width = '500' align='center'>"; 
echo "<tr bgcolor='#99FF00'>";
echo "<td><b>Produto</b></td>";
echo "<td><b>Preco total</b></td>";
echo "<td><b>Size</b></td>";
echo "<td><b>Adicionar</b></td>";
echo "<td><b>Remover</b></td>";
echo "</tr>";
$total = 0;


					  
   $result = mysql_query("SELECT * FROM products WHERE prod_id=$prod_id",$con);
   $row = mysql_fetch_array($result);
   
   $name = $row['prod_name'];
   $price = $row['prod_price'];
 


   $size = mysql_query("SELECT size_list FROM sizes WHERE prod_id=$prod_id",$con);
   $row_size = mysql_fetch_array($size);
   
	$size_list = $row_size['size_list'];
 
 
  
	echo "<tr class='cart_table'>";
	echo "<td align='center'>$name</td>";
	echo "<td align='center'>&pound;$price</td>";
	echo "<td align='center'>$size_list</td>";
	echo "<td align='center'><a href='cart2.php?prod_id=".$prod_id."&action=add'><img src='../images/positive.gif'</a></td>";
	echo "<td align='center'><a href='cart2.php?prod_id=".$prod_id."&action=remove'><img src='../images/negative.gif'</a></td>";
	echo "</tr>";
    
	
  
	// close loop
	
     echo "<tr>";
	 echo "<td align = 'center'><br><b> Sub-Total: </b></td>";
	 echo "<td align = 'center'><br> &pound;$total </td>";
	 echo "<td colspan='3'><a href='cart2.php?prod_id=".$prod_id."&&action=empty'>Esvaziar o Carrinho</a</td>";
	echo "</tr>";
    echo "</table>";
	echo "</form>";
	 echo "</br>";
	 echo "</br>";
   }
 
?>

</div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.