I have a list of dates that is generated from and SQL table:
<form action="deleteMilestone.php" method="GET">
<label class="boldLabel">Project Milestone Dates:</label><br><br>
<div class="dateContainerLeft">
<?php
$result2 = $conn->prepare("SELECT mDate FROM datetable WHERE pId
= '$pId' AND mDate <> '0000-00-00'");
$result2->execute();
$rows2 = $result2->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows2 as $row2) {
$mDate = $row2['mDate'];
?>
<input type="hidden" name="mDate" value="<?php echo $mDate;
?>">
<input type="checkbox" name="mDate"><?php echo $mDate; ?>
<br>
<input type="hidden" name="pId" value="<?php echo $pId; ?>">
<?php } ?>
<br><br>
<button class="buttonMilestone" type="submit" name="milestone"
value="delete">Delete Milestone Date</button>
</div>
</form>
I am trying to delete a specific date when it is checked, the issue I am having is that no matter which date is selected the value that gets passed to the DELETE SQL is always the last date displayed. So if there is a list of 10 dates and I select date[5] when the DELETE SQL runs it deletes date[10] it should delete date[5].
Here is the DELETE SQL(updated to prevent SQL Injection):
if(isset($_GET['mDate'])) {
$sql = "DELETE FROM datetable
WHERE pId = :pId AND mDate = :mDate";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':pId', $pId);
$stmt->bindParam(':mDate', $mDate);
$stmt->execute();
}