I am building an application with php
The form is generated using for loop statement
How do I get the value of each row?
HTML
<form action="submitchecklist.php" method="post">
<table border="2">
<thead>
<th colspan="2">PLUMBING</th>
</thead>
<tbody>
<tr>
<td></td>
<td>
Leakage
</td>
<td>Heater</td>
</tr>
<?php
for ($i = 201; $i <= 215; $i++) {
echo '
<tr>
<td>' . $i . '</td>
<td>
<input type="radio" value="yes" name="leak' . $i . '_[]" id="">Yes
<input type="radio" value="no" name="leak' . $i . '_[]" id="">No
</td>
<td>
<input type="radio" value="yes" name="heat' . $i . '_[]" id="">Yes
<input type="radio" value="no" name="heat' . $i . '_[]" id="">No
</td>
</tr>
'
} ?>
</tbody>
</table>
</form>
I want to get the value of each row from the form
submitchecklist.php
<?php
foreach ($_POST['leak'] as $key => $value) {
echo "<br />";
echo $value;
echo (isset($heat[$key])) ? $leak_no[$key] : "";
}
2
Answers
You could do it this way:
But this
leak' . $i . '_[]
is not very good way to organise your names.You should alter the name of the radio inputs:
This way your originally code in submitchecklist.php works.