i have a form that contains a table which is dynamically created from an mysql query.
Each row contains a persons name and a checkbox. what i am trying to do is have the persons record updated with a 1 if the checkbox is checked or 0 if it is unchecked.
The problem is that when i use the below code, the right number of records are updated but not for the right person. here is the relevant form code:
<?php
while ($row = mysqli_fetch_array($queryresult,MYSQLI_ASSOC)) {
echo '
<tr>
<td align="left">'. ucfirst($row['CustNumber']) .'</td>
<td align="left">'. ucfirst($row['Firstname']) .' '. ucfirst($row['Surname']) .'</td>
<td align="center">
<input type="hidden" name="cid[]" value="'. $row['CustNumber'] .'">
<input type="hidden" name="cbox[]" value="">
<input type="checkbox" name="cbox[]" value="1">
</td>
</tr>';
}
and here is a simplified processing page:
foreach ($_POST['cid'] as $key=>$custid) {
$check = $_POST['cbox'][$key];
if ($check == "1") {
//update customer record with 1 query here
}
else {
//update customer record with 0 query here
}
}
can some tell me where i am going wrong? feel like I'm close but cant put it all together.
Aucun commentaire:
Enregistrer un commentaire