I'm having problems with extracting the data from a radio button form.
It looks like this:
<?php
## color
$stripe = 1;
$att_color=mysql_query("SELECT * FROM product_attributes WHERE products_id ='".$row['products_id']."' AND att_head='colors' AND att_show='1' ORDER BY att_order asc");
if(mysql_num_rows($att_color)!=0)
{
echo "
<table>
<tr>
<td width=\"90%\" align=\"left\" bgcolor=\"#EDEDED\">Color</td>
<td width=\"10%\" align=\"center\" bgcolor=\"#891531\">
<a href=\"#2\" title=\"Yta / Behandling\"><img src=\"images/info.png\"></a>
</td>
</tr>";
while($color_row=mysql_fetch_array($att_color)){
if ($color_row['att_standard'] == 1) { $standard = "checked"; }
echo "
<tr class=".(($stripe++%2==1) ? 'odd' : 'even').">
<td colspan=\"2\" width=\"100%\">
<input name=\"color_name[]\" value=\"".$color_row['att_name']."\" id=\"".$color_row['att_order']."\" type=\"hidden\" />
<input type=\"radio\" name=\"color_selected[]\" id=\"".$color_row['att_order']."\" value=\"".(round($color_row['att_val']*0.85))."\" ".$standard.">
<img src=\"images/colors/".$colorimg."\"> ".$color_row['att_name']."</td>
</tr>";
unset($standard); }
echo "</table>"; }
# END color
?>
Only ONE option is to be allowed. When someone hits submit I* need to get the value AND the corresponding name from that row. However I can't seem to figure the foreach syntax out.
if( isset($_POST['submit']) ) {
$c_selected = $_POST['color_selected'];
$c_name = $_POST['color_name'];
foreach($c_selected as $key => $n) {
echo "<br><br>". $c_selected[$key] ." ".$c_name[$key];
}
The current code gives me the correct value, but the wrong colorname. (always 1st option) How can I get this to work?