In my project, I have a table and I have fetched data to that table using a while loop. Here's is the code for that.
<form action="returnDoc.php" method="post">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
<h3>Return Document</h3>
</div>
</div><br><br>
<table class="table table-responsive-lg table-hover">
<tr>
<th>
No
</th>
<th>
Document ID
</th>
<th>
Put the tick for returns
</th>
</tr>
<?php while ($_r = mysqli_fetch_assoc($q_set)) { ?>
<tr>
<td>
<?php echo $_r['number']; ?>
</td>
<td>
<?php echo $_r['doc_id']; ?>
</td>
<td>
<input type="checkbox" name="return" value="<?php echo $_r['doc_id']; ?>" />
</td>
</tr>
<?php } ?>
</table>
</div>
<div class="col-md-2">
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
<div class="col-md-4">
<input type="submit" value="SEND TO DSO" name="submit" class="btn btn-light"/>
</div>
</div>
</form>
As you can see, the table is inside a form and there's a checkbox for each row in the table.
This is a screenshot of my database table. As you can see there's a field called availability and values for them are 'locked'. When I click submit, I want to update these locked fields into 'returned' where checkbox is ticked. Others which are not ticked should not be updated.
So, here's what I did.
if (isset($_POST['submit'])) {
$update_query = "UPDATE req SET availability = 'returned' WHERE doc_id='$_POST[return]'";
mysqli_query($conn, $update_query);
}
My problem is, this query updates only the last row I ticked because it gets the value after loop is finished. It doesn't update all the rows I select. So if you have any idea how to achieve this, please help me.