I am trying to add on some checkboxes with a form that is already made for adding/editing products.
I have been able to add on radio buttons in the past. To do this I have used a switch like so:
if (!isset($pInfo->color_id))
$pInfo->color_id = '1';
switch ($pInfo->color_id) {
case '1': $green_color_id = true;
break;
case '2': $turquoise_color_id = true;
break;
default: $green_color_id = true;
}
However now, since I want to use checkboxes I don't think I can use a switch like that, since I want multiple colors to be picked and each one of them inserted into the database as a separate field.
Here is my php/html for creating the checkbox:
<tr>
<td class="main">Colors</td>
<td class="main">
<?php echo ' Green' . tep_draw_checkbox_field('color_id', '1', $green_color_id) . ' Turquoise' . tep_draw_checkbox_field('color_id', '2', $turquoise_color_id);
?>
</td>
</tr>
this is my query for actually inserting it in the database:
if (!isset($HTTP_GET_VARS['color_id'])) {
tep_db_query("insert into " . TABLE_PRODUCTS_TO_COLORS . " (products_id, color_id) values ('" . (int)$products_id . "', '" . (int)$color_id . "')");
}
else {
mysql_query("update " . TABLE_PRODUCTS_TO_COLORS . " SET color_id = '" . (int)$color_id . "' WHERE products_id ='" . (int)$products_id . "'");
}
this is how the custom function tep_draw_checkbox_field is defined:
function tep_draw_checkbox_field($name, $value = '', $checked = false, $compare = '') {
return tep_draw_selection_field($name, 'checkbox', $value, $checked, $compare);
}
I'm pretty sure I will need to store the selected values into an array, and then change the query to use the array. I'm not sure how to get started or if that is even right though. Any help is vastly appreciated!
$_GETinstead.