I have a list that is populated from a database table as below.
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td>
<input type="checkbox" name="name[]" value="<?php echo
$row['AnalysisID']; ?>">
<?php echo $row["CustomerName"]; ?>
<input type="hidden" name="Site[]" value="<?php echo $row["Site"]; ?>">
<input type="hidden" name="Unit[]" value="<?php echo $row["Unit"]; ?>">
</td>
<td><?php echo $row['Site']; ?></td>
<td><?php echo $row['Unit']; ?></td>
</tr>
<?php
}
?>
This displays the data perfectly, and in inspect all data is correct.
However I want to be able to check the various check-boxes and insert those rows to another table.
to achieve this I am using:
$counter = count($_POST["name"]);
for($x=0; $x<=$counter; $x++){
if(!empty($_POST["name"][$x])){
$PI_NO = mysql_real_escape_string($_POST["name"][$x]);
$CUSTOMER_NAME = mysql_real_escape_string($_POST["Site"][$x]);
$PI_ADDRESS = mysql_real_escape_string($_POST["Unit"][$x]);
$qry="INSERT INTO test1 (AnalysisID, Elem, Lube) VALUES ('$PI_NO','$CUSTOMER_NAME','$PI_ADDRESS')";
mysql_query($qry);
}
}
The problem is it doesn't matter what rows I check it always inserts the first in the list, it inserts the correct number just from the start of the list.
For example if I check the last 4 in the list I get the first 3.
Any pointers would be a great help.