Put the row ID in a hidden input. The you can use $_POST['id']
to know which question it’s the answer to.
while (counter !=0) {
echo '
<form method="post">
<input type="radio" id="answerA-' . $row['id'] . '" name= "answer-' . $row['id'] . '" value="answerA" required>
<label for="answerA-' . $row['id'] . '"> ' . $row['answerA'] . ' </label><br>
<input type="radio" id="answerB-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerB">
<label for="answerB-' . $row['id'] . '"> ' . $row['answerB'] . ' </label><br>
<input type="radio" id="answerC-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerC">
<label for="answerC-' . $row['id'] . '"> ' . $row['answerC'] . ' </label><br>
<input type="radio" id="answerD-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerD">
<label for="answerD-' . $row['id'] . '"> ' . $row['answerD'] . ' </label><br>
<input type="hidden" name="id" value="' . $row['id'] . '">
</form>
'
;
}
There are other issues. IDs have to be unique, so you should include the question ID in the IDs of each of the answers.
All the names in a radio group have to be the same, that’s how the browser knows they’re alternative answers to the same question. But each form needs to have distinct radio groups. So you should take A
, B
, C
and D
out of the radio button names, but add in the question ID.