Hi there. Long time lurker, first time poster, LOL. It should go without saying that I'm a newbie. But I've actually been making tons of progess and figuring things out on my own -- in large part due to all the assistance available here and in the manual.
I've been trying to learn about checkbox arrays and am thoroughly confused because there seem to be a couple different ways of looping through them.
I have a massive form that will be utilizing multiple arrays of checkboxes. I'm trying to tackle the first one. (Baby steps! :queasy: )
Each of my checkboxes in my first array are coded as follows in the HTML:
<input type="checkbox" name="chk_ShopSpecialty[0]" id="chk_ShopSpecialty[0]" value="1">
They run from 0 to 26.
Any problems there?
Then onto my code to read the array. I want to read each value to see if it's checked, and if not, assign it a value of 0. Then, of course, I want to insert the entire record into the database.
I want to get the basic code down first before tackling the next steps. What is the best way to approach this?
<? php
if (isset($_POST['submit'])){
$chk_ShopSpecialty = array();
// is this how to correctly declare the array?
// is this the correct location TO declare it?
//METHOD ONE I'VE SEEN:
while
(list($key,$value) = each($chk_ShopSpecialty))
{
print_r($value);
}
//METHOD TWO:
for ($x = 0; $x < sizeof($chk_ShopSpecialty); $x++) {
echo 'Value='.$chk_ShopSpecialty[$x].'<br>';
}
}
?>
My problem is that neither of these methods is displaying anything. I want to be able to get this straight before I try to go any further. What am I doing wrong?
Thanks in advance for your help!