Total newbie here, and desperate for help as I stuggle through my first attempt at looping through arrays. 🙁
I have a series of 28 checkboxes formatted as follows (numbered 0 - 27):
<input type="checkbox" name="chk_ShopSpecialty[0]" id="chk_ShopSpecialty[0]" value="1">
If the box is checked, I want a value of 1 inserted into that database field; if it is unchecked, I want the value to be 0. What I've done so far is below, and everything is working as I expect.
if (isset($_POST['submit'])){
$result = count($_POST['chk_ShopSpecialty']);
echo "count of array = $result<br>";
while (list($key,$value) = each($_POST['chk_ShopSpecialty']))
{
echo "$key => $value<br>";
}
for ( $x=0; $x<28; $x++ ) {
if (array_key_exists($x, $_POST['chk_ShopSpecialty'])) {
$strTemp[$x] = 1;
}
else {
$strTemp[$x] = 0;
}
echo "strTemp$x = $strTemp[$x]<br>";
}
}
My question now is: how do I get the series of values returned from the last function so that I can get them into a $sql string along the lines of
$sql = "UPDATE shop_svc SET engassem = '$strTemp0', flowbench = '$strTemp1'
WHERE CompanyID = '$compID'";
Any suggestions how to accomplish this? Is it possible? And have I done anything wrong so far that should be changed?
Thanks in advance.