I have a form where the answers will be registered and if there is also a field to mark the true one:
...
<tr>
<td style="font-weight: bold">1.</td>
<td><input type="text" name="Respostas[]" class="form-control"></td>
<td style="text-align: center"><input type="radio" name="Verdadeira[]" value="S"></td>
</tr>
<tr>
<td style="font-weight: bold">2.</td>
<td><input type="text" name="Respostas[]" class="form-control"></td>
<td style="text-align: center"><input type="radio" name="Verdadeira[]" value="S"></td>
</tr>
<tr>
<td style="font-weight: bold">3.</td>
<td><input type="text" name="Respostas[]" class="form-control"></td>
<td style="text-align: center"><input type="radio" name="Verdadeira[]" value="S"></td>
</tr>
...
I'm recovering as follows to register with the bank:
if ($_POST) {
for($i = 0; $i < count($_POST["Respostas"]); $i++){
mysqli_query($conexao,"INSERT INTO pe_perguntas VALUES(null,'" . $_SESSION["IdPerguntas"] . "','" . $_POST["Respostas"][$i] . "','" . $_POST["Verdadeira"][$i]."');";
}
But if I mark the third question as true, it always returns the first answer to me as the true one, not the third. See below the print ():
INSERT INTO pe_perguntas VALUES(null,'2','Resposta 1','S');
INSERT INTO pe_perguntas VALUES(null,'2','Resposta 2','');
INSERT INTO pe_perguntas VALUES(null,'2','Resposta 3','');