vinpkl
April 9, 2010, 4:44pm
1
hi all
i m able to echo all the checkboxes selected through the below code
<input type="checkbox" value="Battery" name="checkbox[]" id="checkbox[]"
/>
for ($i=0; $i<count($_REQUEST['checkbox']);$i++) {
echo "chosen<br />$i. ".$_REQUEST['checkbox'][$i];
}
ouput is
0. battery
1. rocket
2. pineapple
but i want to insert all selected checkboxes values in database.
so what should i write in my query
$query = "insert into checkbox table (checkboxes) values()"
vineet
r937
April 9, 2010, 5:36pm
2
design your table so that each checkbox value is a separate row
vinpkl
April 9, 2010, 5:38pm
3
hi r937
i have 30 checkboxes in my form.
so i have to make 30 rows or fields in my database.
is there any alternative
vineet
r937
April 9, 2010, 5:49pm
4
30 coumns or 30 rows if you want to use one value per column/row
other alternatives are multiple values in a single column (which violates first normal form) or a bitmap (which requires application code to interpret)
vinpkl
April 9, 2010, 5:53pm
5
hi r937
yes i would like to insert all selected checkboxes values in one single column with a comma separator.
but that you say violates the form.
normally what is adapted by programmers.
i m new to it.
vineet
normally you would not store comma separated values. you would insert one new row for each value.