I have an html form that passes an array into php and then does a for loop to print out values. This is the code that I have
$payloads = $_POST['topay'];
$loadNum = $_POST['loadnum'];
$unit = $_POST['unit'];
$driver = $_POST['driver'];
for($i=0;$i<count($payloads);$i++)
{
echo $payloads[$i];
echo "<br>";
echo '<td width="50" valign="top">'.$loadNum[$i].'</td>';
echo '<td width="50" valign="top">'.$unit[$i].'</td>';
echo '<td width="150" valign="top">'.$driver[$i].'</td>';
}
the $_POST['topay'] is a checkbox array that I pass in where only the items that are checked will come through. For example in the form that I pass to php there are multiple check boxes, and it should only pass the ones that are checked. When I do the first echo in the for loop it correctly prints out the values, but the echos within the do not.
Values:
$loadNum = [5,6]
$unit = [101,103]
driver = ["joe", "mike"]
When both of these checkboxes are checked, the output works correctly. When the first checkbox is checked, the output works correctly. However, if I only check the second one (6, 103, "mike"), the output still comes out for (5,101,"joe")
EDIT: here is the HTML code that i send to this php page:
echo '<form action="statement.php" target="_blank" METHOD="post">';
echo '<td><input type="checkbox" name="topay[]" value="'.$loadNumber.'" checked></td>';
echo '<td width="70"><input type="hidden" name="loadnum[]" value="'.$loadNumber.'" />'. $loadNumber.'</td>';
echo '<td width="70"><input type="hidden" name="unit[]" value="'.$unit.'" />' .$unit.'</td>';
echo '<td width="150"><input type="hidden" name="driver[]" value="'.$driver.'" />' .$driver.'</td>';
?>
<p><input type="submit" name="sumbit" value="Create Statement" /></p>