I am new to PHP and SQL and trying to figure out how I can make the HTML Approve (submit) button interact specifically with its corresponding record. Currently when the Approve button is clicked, each of the fields are updated, but the top (first) record available is always the one updated. I would like the user to be able to skip the first record and update a different record. Any and all suggestions/help are greatly appreciated.
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('there was a problem connecting to the database' . mysql_error());
$sql = "SELECT Part, Lot, Qty, AnodTemp, Amp, SealTemp, PerformedBy, DateTimePerformed, FinalAnodThickness, QtyPass, FinalSealCheck, CheckedBy, DateTimeChecked, id FROM logs";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$unapproved = $row['CheckedBy'];
if($unapproved == null)
{
echo "<br><br><br> Part: " . $row['Part']. " / Lot: " . $row['Lot']. " / Qty: " . $row['Qty']. " / AnodTemp: " . $row['AnodTemp']. " / Amp: " . $row['Amp']. " / SealTemp: " . $row['SealTemp']. " / PerformedBy: " . $row['PerformedBy']. " / ID: " . $row['id']; ?>
<form action="adminapproval.php" method="post">
Final Anod Thickness:<br>
<input type="text" name="FinalAnodThickness">
<br><br>
Qty Pass:<br>
<input type="text" name="QtyPass">
<br><br>
Final Seal Check:<br>
<input type="text" name="FinalSealCheck">
<br><br>
<input type="submit" id="submit" value="Approve" name="submit">
<br><br>
</form>
_____________________________________________________________________<br>
<?php
if (isset($_POST['submit']))
{
$FinalAnodThickness= $_POST['FinalAnodThickness'];
$QtyPass= $_POST['QtyPass'];
$FinalSealCheck= $_POST['FinalSealCheck'];
$CheckedBy= $_SESSION['CheckedBy'];
$id = $row['id'];
$sql = "UPDATE logs SET FinalAnodThickness = '$FinalAnodThickness', QtyPass = '$QtyPass', FinalSealCheck = '$FinalSealCheck', CheckedBy = '$CheckedBy', DateTimeChecked = now() WHERE id = $id ";
$conn->query($sql);
break;
$conn->close();
echo "Record Updated.";
header("Location: adminapproval.php");
}
}
}
}
echo "<br><br> No further items need to be approved at this time.";
?>