Ok, well the problem here is that all of the related form fields with an array in the name must match their respective checkbox. In lamens terms, everything related to a set checkbox must be set, and nothing else.
What would work is passing an iterative count to the parameter of the array to mark which field should be set. Then you can easily get their name by their count.
So your HTML should look like:
PHP Code:
<table border = 1 align="center">
<?php
while($result = mysql_fetch_array($query))
{
$c++;
?>
<tr>
<td bgcolor="#666666">
<input name="checkbox[<?php echo $c; ?>]" type="checkbox" id="checkbox[<?php echo $c; ?>]" value="<?php echo $c; ?>" />
</td>
<td align="center"><input name="customerid[<?php echo $c; ?>]" type="text" id="customerid" value="<?php echo $result['customer_id']; ?>"></td>
<td align="center"><input name="name[<?php echo $c; ?>]" type="text" id="name" value="<?php echo $result['name']; ?>"></td>
<td align="center"><input name="amount[<?php echo $c; ?>]" type="text" id="amount" value=" "></td>
</tr>
<?php
}
?>
<input type="submit" name="submit" value="Submit" />
</table>
And your iterative loop should look something like this:
PHP Code:
if(isset($_POST['submit']))
{
// here i want to to update my table based on customerid. I am unable to pass the values in a loop to table
foreach($_POST[checkbox] as $chk) {
$amount = $_POST['customerid'][$chk];
$agent = $_POST['name'][$chk];
$amount = $_POST['amount'][$chk];
}
}
By assigning the value of the checkbox to the current count, and having all of the other fields with the same count, that checkbox can now be associated with those form fields.
Bookmarks