I am trying to update a MySQL field from 0 to 1 with a submit button. The table displays around 50 rows and has a submit button for each row.
I think I am misunderstanding something fundamental to where either the variable is set or the hidden input should be in relation to the while loop. I realise Ajax could be an option but trying to learn one thing at a time. I am expecting the button to update only the row that the submit button is displayed in and instead like so many other posts it updates only the very last row.
<?php
    include 'config.php';
?>
<?php
    
    $result = mysqli_query($con,"SELECT * FROM ppm");
    echo    '<table>
                <tr>
                    <td>ID</td>
                    <td>Extinguisher Location</td>
                    <td>ID No.</td>
                    <td>Type</td>
                    <td>Done?</td>
                    <td>?</td>
                    <td>Time Stamp</td>
                </tr>';
    echo "<form action='' method='post'>";
    
    while($row = mysqli_fetch_array($result))
        {
            $id = $row['id'];
            echo "<tr>";
            //echo "<input type='hidden' name='id' value='" . $id . "'>";
            echo "<td>$id</td>";
            echo "<td>" . $row['pretty_name'] . "</td>";
            echo "<td>" . $row['ident'] . "</td>";
            echo "<td>" . $row['type'] . "</td>";
            echo "<td>  <input value='done' name='Submit' type='submit' /> </td>";
            echo "<td>" . $row['done'] . "</td>";
            echo "<td>" . $row['updated_at'] . "</td>";
        }
                     
    echo "</form>";
    echo "</tr>";
    echo "</form>";
    echo "</table>";
    echo "<input value='Reset All' name='reset_all' type='submit' />";
?>
<?php
if(isset($_POST['Submit']))
{
    $sql = "UPDATE ppm SET done=1 WHERE id = '$id'";
    mysqli_query($con, $sql) or die("Cannot update");
}
?>
 
    