Hi all,

Im trying to add sizes to the cart. However, i cant pass size over. please help.

$result = $db->query($sql);
$output[] = '<ul>';

while ($row = $result->fetch()) { 

  $output[] = '<br><font color="837F77"size="6">'.$row['name'].' </font><br></br> S$'.$row['price'].'<br></br>';

 $output[] = '<select name="size">
<option disabled="disabled" selected value="NA" >Size</option>';

     if ($row[small_qty]== 0){  
  $output[] = ' <option disabled="disabled" value="NA" >Small</option>';
}else { 
  $output[] = '<option value="s">Small</option>';
 } 
      if ($row[medium_qty]== 0){  
  $output[] = ' <option disabled="disabled"  value="NA" >Medium</option>';
 }else {
  $output[] = '<option value="m">Medium</option>';
 } 
      if ($row[large_qty]== 0){  
  $output[] = ' <option disabled="disabled"  value="NA" >Large</option>';
 }else {
 $output[] = ' <option value="l">Large</option>';
 } 
 $output[] = '</select>';

    $output[] = '<br></br><a href="cart.php?action=add&product_id='.$row['product_id'].'&p='.$size.'" value="Submit"> <img src="image/addbutton.png" border="0" /></a></a> 
</li>';

}
$output[] = '</ul>';
echo join('',$output);

GET

<?php

// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
$size= $_GET['p'];

$size1 = $_POST['size'];

//if there is an product_id and that product_id doesn't exist display an error message
if($product_id && !productExists($product_id)) {
    die("Error. Product Doesn't Exist");
}

echo $size;
echo $action ;
echo $size1 ;
echo $_GET['product_id'];
switch ($action) {
    case 'add':
        if ($cart) {
            $cart .= ','.$_GET['product_id'];

        } else {
            $cart = $_GET['product_id'];

        }
        break;

Any other idea?
Help is much appreciated, im sorry , im still learning

Is there a reason you are using

<select>
    <option></option>
</select>
<a href="..."></a>

Instead of

<form>
    <select>
        <option></option>
    </select>
    <input type="submit [or button]" />
</form>

? The second would make things easier on you. The way you're doing it now requires JavaScript to pass the value correctly. Putting $size into the URL in the <a> tag won't work, because $size has no value there and will not change based on your dropdown selection.

Yes ! finally i can pass the size .
Thank you so much EvolutionFallen .

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.