Hello again,
I have a form that has several options to select features of a computer (vga, dvi, ethernet, modem, zip, etc.) through checkboxes. In the database, it is stored as a 0/1 (false/true). What I am working on is an edit form to make changes if necessary, but I am having trouble populating the checkboxes that are marked as true already.
while($cmp = $_SESSION['DB']->fetch_array($cmpQ)){
$chkbxs = array('vga', 'ps2', 'usb', 'firewire', 'ethernet', 'cddvd', 'fdd', 'zip', 'dvi', 'serial', 'sound', 'wireless', 'modem', 'smartm');
foreach ($chkbxs as $value) {
$check="";
if ($cmp[$value] == 1) {
$check = "checked";
echo ''.$value.' <br/>';
}
...more code, form below
This does it it should. I have an entry with vga, firewire, smartm, and zip selected, and $value returns that properly.
In the form, this is how I have it set up.
echo '<input type="checkbox" name="hardware[]" value="vga" '.$check.'>';
Right now, every checkbox is selected, meaning that for some reason, $cmp[$value] == 1 is affecting all checkboxes in the form, even though it is only returning the 4 that are marked as selected when I echo $value.
Am I missing something minor or am I going about this the wrong way?