I've come up completely empty-handed on how to make this work.
What I have is a table listing all results from the database, at the side of each row I have a button that -hopefully- allows people to "retire" that result with a simple 0/1 check. Now, the link itself works, but it submits every single button on the page, even though just one has actually been clicked.
I did try this at first as a form with a single submit button for each row; same result. You can see that there are a series of buttons (edit, transfer, breed) and then the (retire) button that should trigger an update marking a column in the db with a '1', from being a '0.'
How can I resolve this?
Image for assistance in visualization; the last button on the far right of each row should run this update when clicked.
Showing visualization: https://i.stack.imgur.com/CulHt.png
Showing SQL (which is correct): https://i.stack.imgur.com/hMbKg.png
echo '<a href="edit_horse.php?id='. $horseID .'" class="btn btn-sm btn-icon btn-light me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit"><i class="fas fa-pencil-alt"></i></a>';
echo '<a href="transfer_horse.php?id='. $memberID .'&horse='. $horseID .'" class="btn btn-sm btn-icon btn-light me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Transfer"><i class="fas fa-exchange-alt"></i></a>';
echo '<a href="breed_horse.php?id='. $memberID .'&horse='. $horseID .'" class="btn btn-sm btn-icon btn-light me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Breed"><i class="fas fa-venus-mars"></i></a>';
$retireSQL = "SELECT * FROM horses WHERE id = '$horseID'";
$retire = mysqli_query($sqlconnect, $retireSQL);
if(mysqli_num_rows($retire) != 0){
$retire_link = '<a class="btn btn-sm btn-icon btn-light me-2" href="my_horses.php?page='. $page .'&id='. $memberID .'&horse='. $horseID .'&action=retire" data-bs-toggle="tooltip" data-bs-placement="top" title="Retire"><i class="fas fa-heart-broken"></i></a>';
}
if(isset($horseID)) {
if (isset($action)) {
if ($action == 'retire') {
$retire_insertSQL = "UPDATE horses SET retired = 1 WHERE id = '$horseID'";
$retire_insert = mysqli_query($sqlconnect,$retire_insertSQL) or die(mysqli_error($sqlconnect));
echo $retire_insertSQL;
}
}
}
echo $retire_link;