How can I send more than one value from several radio buttons to the database?

0

The questions are all taken from the database, but I can not send more than one, and when I send, it does not even enter the database.

Shipping 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");
    }

?>

Radio button code:

$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>
    
asked by anonymous 19.01.2017 / 20:38

1 answer

0

As for not being in the database, you should check the line where the query is constructed, the syntax is wrong.

The correct one would be something like:

$resposta = "Insert INTO aluno_teste(Resposta) VALUES('".$resposta."')";

Regarding the fact that "can not send more than one" you refer to submitting the form? That is, when submitting the $ _POST is not filled with the answers to all the questions?

    
20.01.2017 / 01:43