0
The questions are all taken from the database, but I can’t send more than one, and when I send them, I don’t even enter them into the database.
Sending Code:
<?php
if (!isset($_SESSION)){session_start();}
echo $resposta=$_POST['resposta-1'];
echo "<br>";
echo $user=$_POST['user']; echo "<br>";
$inst0="Select Resposta from aluno_teste ";
$result0=mysqli_query($conn,$inst0);
echo $numlinhas1=mysqli_num_rows($result0);
//echo var_dump($_POST);
if ($numlinhas1 == 0)
{
$resposta="Insert INTO aluno_teste(Resposta,) VALUES(' ','".$resposta."')";
if(!mysqli_query($conn,$inst0)){
echo 'erro :'. mysqli_error($conn);
}else{
echo "<br>";
echo 'Linhas alteradas: '. mysqli_affected_rows($conn);
}
$_SESSION['mensagem'] ="Respostas enviadas";
//header("Location:IndexTestes.php");
}
?>
Code of radio Buttons:
$instS='Select * from perguntas';
$query = mysqli_query($conn,$instS);
while ($row = mysqli_fetch_assoc ($query))
{
echo"<br>";
echo"<center><fieldset style='border:solid; width:500px;'>";
echo" <legend style='background: #FF9; width:150px; border: solid 1px black;
-webkit-border-radius: 8px; -moz-border-radius: 8px;
border-radius: 8px; padding: 6px;'> Questão: ".$row['idPergunta']."";
echo"</legend>";
echo "<center> <h4><b> Pergunta: </h4></center></b>";
echo"<center>"
.$row['textoPerguntas'].""; //Buscar a pergunta a base de dados
echo"<center>";
echo " <h4><b> Resposta: </h4></b>";
$radioname = "resposta-".$row['idPergunta'];
//$items = Array($row['RespostaCorrecta'],$row['RespostaErrada1'],$row['RespostaErrada2'],$row['RespostaErrada3']);
?>
<fieldset name="pergunta-<?php echo $radioname; ?>" id="pergunta-<?php echo $radioname; ?>" >
<?php
// echo " <input type='radio' required name='pergunta-".$radioname."' id='pergunta-".$radioname."' > ".$items[array_rand($items)]."";
echo " <input type='radio' required name='".$radioname."' id='".$radioname."' value='".$row['RespostaErrada3']."' > ".$row['RespostaCorrecta']."";
echo "<br>";
echo " <input type='radio' required name='".$radioname."' id='".$radioname."' value='".$row['RespostaErrada3']."' > ".$row['RespostaErrada1']."";
echo "<br>";
echo " <input type='radio' required name='".$radioname."' id='".$radioname."' value='".$row['RespostaErrada3']."' > ".$row['RespostaErrada2']."";
echo "<br>";
echo " <input type='radio' required name='".$radioname."' id='".$radioname."' value='".$row['RespostaErrada3']."' > ".$row['RespostaErrada3']."";
echo "<br>";
?>
</fieldset>
<br>
<?php
echo "</fieldset></center>";
}
?>
<center>
<button onClick='return confirm("Deseja enviar?");' class='btn btn-default glyphicon glyphicon-ok' type='submit'> Enviar</button>
</center>
</form>
Exactly. Because I have my radio Buttons with random names, and it gets complicated for me to be able to send a value ...
– Paulo
Paulo, you see, the random name of the radio Buttons has nothing to do with the fact that the values are not going via $_POST post post Ubmit, you know? What would justify this malfunction would be a syntax error for example.
– Jotta Jorge