All of my other form data is stored correctly in the db except for my checkbox data. This column in my table is empty.
I have this checkbox group on my form:
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item1">I tem1
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item2">I tem2
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item3">I tem3
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item4">I tem4
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item5">I tem5
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item6">I tem6
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item7">I tem7
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item8">I tem8
This, among other things, is passed to a confirmation page where I have this:
---------------------------------------
<?php
if(!isset($_POS T['cbItems']))
{
//array is empty
$_POST['cbItems'] = array();
echo "None selected.";
}
else
{
//must do this for checkboxes (passing multiple values)
foreach ($_POST['cbItems'] as $items)
{
echo " - $items";
}
}
?>
<input type='hidden' name='cbItems' value='<?php echo $_POST['$items'];?>'>
---------------------------------------
On the next page (last page) I connect to the db and insert into the table:
---------------------------------------
$cbItems = array($_POST['items']);
$cbItems_array = implode(",", $cbItems);
include 'db_connect.php ';
$query_insert = "INSERT INTO healthed_worksh op (date, fname, lname, phone, email, org, dlSubject,
other, dlMonth, dlDay, dlYear, dlTime1, dlTime2, location, attend, cbItems, taAdd)".
"VALUES (now(),'".$_POS T['fname']."', '".$_POST['lname']."', '".$_POST['phone']."', '".$_POST['email']."',
'".$_POST['org']."', '".$_POST['dlSubject']."', '".$_POST['other']."', '".$_POST['dlMonth']."',
'".$_POST['dlDay']."', '".$_POST['dlYear']."', '".$_POST['dlTime1']."', '".$_POST['dlTime2']."',
'".$_POST['location']."', '".$_POST['attend']."', '$cbItems_array ', '".$_POST['taAdd']."')";
echo "$query_insert" ;
mysql_query($qu ery_insert) or die(mysql_error ());
mysql_close;
?>
---------------------------------------
Am I missing something glaringly obvious? Thanks in advance!
I have this checkbox group on my form:
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item1">I tem1
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item2">I tem2
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item3">I tem3
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item4">I tem4
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item5">I tem5
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item6">I tem6
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item7">I tem7
<input name="cbItems[]" type="checkbox" id="cbItems" value="Item8">I tem8
This, among other things, is passed to a confirmation page where I have this:
---------------------------------------
<?php
if(!isset($_POS T['cbItems']))
{
//array is empty
$_POST['cbItems'] = array();
echo "None selected.";
}
else
{
//must do this for checkboxes (passing multiple values)
foreach ($_POST['cbItems'] as $items)
{
echo " - $items";
}
}
?>
<input type='hidden' name='cbItems' value='<?php echo $_POST['$items'];?>'>
---------------------------------------
On the next page (last page) I connect to the db and insert into the table:
---------------------------------------
$cbItems = array($_POST['items']);
$cbItems_array = implode(",", $cbItems);
include 'db_connect.php ';
$query_insert = "INSERT INTO healthed_worksh op (date, fname, lname, phone, email, org, dlSubject,
other, dlMonth, dlDay, dlYear, dlTime1, dlTime2, location, attend, cbItems, taAdd)".
"VALUES (now(),'".$_POS T['fname']."', '".$_POST['lname']."', '".$_POST['phone']."', '".$_POST['email']."',
'".$_POST['org']."', '".$_POST['dlSubject']."', '".$_POST['other']."', '".$_POST['dlMonth']."',
'".$_POST['dlDay']."', '".$_POST['dlYear']."', '".$_POST['dlTime1']."', '".$_POST['dlTime2']."',
'".$_POST['location']."', '".$_POST['attend']."', '$cbItems_array ', '".$_POST['taAdd']."')";
echo "$query_insert" ;
mysql_query($qu ery_insert) or die(mysql_error ());
mysql_close;
?>
---------------------------------------
Am I missing something glaringly obvious? Thanks in advance!
Comment