Hi , I am using an explode function to split some comma separated colors into a drop down list.

<?php

// Split the string up into an array of values
$dropdown_data = explode(",", $row_rsApparel['Item_Colors']);


// Output a dropdown
echo '<select name="color" id = "color">';
foreach($dropdown_data as $key => $value) {
  echo '<option value="'.$key.'">'.$value.'</option>';
}
echo '</select>';
?>

The drop down works perfectly but I can't seem to get that info into the cart. If I use a standard drop down list in dreamweaver, no problem binding that to the cart. Just not sure how to bind the selection from a php generated list into the cart?

any help would surely be appreciated.

thanks nigel

Member Avatar for diafol

You use the $_POST array variable in your form handling routine to get the select value, namely $_POST in your case. Once you get this, simply use it in your update/insert SQL query.

Thanks so much ardav, I'm close, I am getting info into the cart from that drop down, but it is putting the number of the array into the cart instead of the color name (red,blue,etc.)

I'ver tried this but no luck:

"".((isset($_POST["Color2.$value"]))?$_POST["Color2.value"]:"")  ."";

I'm not sure how to get the actual color value in syntax wise. Kind of new to php.

Member Avatar for diafol

This is because your the $_POST is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

echo '<select name="color" id = "color">';
foreach($dropdown_data as $value) {
  echo '<option value="'.$value.'">'.$value.'</option>';
}
echo '</select>';

I think that should work.

This is because your the $_POST is picking up the array 'key' value and not the value displayed in the dropdown. Do this:

echo '<select name="color" id = "color">';
foreach($dropdown_data as $value) {
  echo '<option value="'.$value.'">'.$value.'</option>';
}
echo '</select>';

I think that should work.

Thanks so much ardav, I understand now. Appreciate your quick reply.

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.