Hidden input gets wrong ID

Asked by At

I have a php scripts whit a table thats sorts after time. in that table i have a check box to mark if somthings is deleverd and i have a hidden input thats get the id. it worked yesterday but know it gets the id lowest on the table.

$sql = "SELECT * FROM `bestalning` WHERE lev=0
ORDER BY tid";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
echo "<form method='POST' action='ID_change.php'>";
echo "<div class='continer bg-vit table-rsponsive-sm '><table class='table'><thead class='thead-dark'>
<tr><th >".'Lev'."</th><th>".' '."</th><th >".'Artikelnr'."</th><th >".'Antal'."</th>
<th >".'Singnatur'."</th><th >".'Önskad ankomst'."</th><th >".'Skickad'."</th></tr></thead></div>";
while($row = mysqli_fetch_array($result)){
    echo "<tbody><tr><td><input style='margin-right:5px;' name='levJA' type='checkbox' value='1'></td><td>
    <input style='margin-right:5px;' name='RowID' type='hidden' value='".$row['ID']."'></td><td>".$row['artikelnr']."</td>
echo " <input class='btn btn-dark m-1' type='submit' value='submit'></form>";


  $Lev = $_POST['levJA'];
$ID = $_POST['RowID'];

$sql = "UPDATE bestalning SET lev='".$Lev."' WHERE ID='".$ID."'";
echo $sql;
if (mysqli_query($conn, $sql,)) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . mysqli_error($conn);


0 Answers