...

View Full Version : Using checkboxes with mysql database



sackstein
11-21-2011, 03:46 PM
I am trying to add on some checkboxes with a form that is already made for adding/editing products.

Here is my php/html for creating the checkbox:


<table>
<tr>
<td class="main">Colors</td>
<td class="main">
<?php echo '&nbsp;Green' . tep_draw_checkbox_field('color_id[]', 1, in_array('1', $pInfo->color_id)) . '
&nbsp;Turquoise' . tep_draw_checkbox_field('color_id[]', 2, in_array('2', $pInfo->color_id)); ?></td>
</tr>
</table>


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);
}

and here is the query:



<?php
// First, delete all n entries of colors-to-products
tep_db_query("delete from " . TABLE_PRODUCTS_TO_COLORS . " WHERE products_id = '" . (int)$products_id . "'");

// now insert colors from form-request
if (is_array($_GET['color_id'])) {
foreach ($_GET['color_id'] as $colorid) {
tep_db_query("insert into " . TABLE_PRODUCTS_TO_COLORS . " (products_id, color_id) values ('" . (int)$products_id . "', '" . (int)$colorid . "')");
}
}

?>


Here is the full document: http://pastebin.com/pjvuGUkH

I am trying to get the colorid array into the PRODUCTS_TO_COLOR table I have in the database. So far I have the correct product ID entering the table but cannot seem to get the color_id field correctly into the database it just always gives me 0.

I believe it has to do with the way that i am using the array. If anyone can have a look that would be greatly appreciated.

Lines of interest in the above document are:
252 (the sql)
430 (the array)
615 (the actual checkbox)

Any help is greatly appreciated!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum