Passing checkbox values

2

Good afternoon,

I need to pass selected values from a checkbox to a page via a form via Post and save them to a database, but I can not, could you help me?

Follow the code:

Form:

<form class="form-horizontal" method="POST" action="operacoes.php?action=GeraProva">
            <div align="center" style="margin-top:200px;">
                <div class="control-group">
                    <label class="labelTrab" for="txtNmMod">Módulo:</label>
                    <input id="txtNmDis" name="txtNmMod" type="text" class="input-mini" value="<?php echo $dsmodulo ?>" disabled="disabled"><br/>
                    <?php if($valProvas > 0) {?>
                        <label class="labelTrab" for="txtNrProva">Prova:</label>
                        <input id="txtNmDis" name="txtNrProva" type="text" class="input-mini" value="<?php echo $cdprova ?>" disabled="disabled"><br/>
                    <?php }?>
                    <table border='1'>
                    <tr>
                        <th>Selecionar</th><br/>
                        <th>ID</th><br/>
                        <th>Descrição</th><br/>
                        <th>Disciplina</th><br/>
                    </tr>
                    <?php 
                        while($row = mysql_fetch_array($var)) 
                        {
                            $ar = $row["cod_disc"];
                            $aux = mysql_query("select nome_disc from tb_disciplinas where cod_disc = '$ar'");
                            $ftc1 = mysql_fetch_array($aux);
                            $nmdisc = $ftc1["nome_disc"];
                            $id = $row["cdpergunta"];
                            echo "<tr>";
                            echo "<td><input type='checkbox' name='checkPerg[]'/></td><br/>";
                            echo "<td>" . $row["cdpergunta"] . "</td><br/>";
                            echo "<td>" . $row["dspergunta"] . "</td><br/>";
                            echo "<td>" . $nmdisc . "</td><br/>";
                            echo "</tr>";
                        }
                    ?>
                    </table>
                </div>
                <div style="margin-top:5px;">
                        <button id="singlebutton" name="btnPesquisa" class="btn btn-primary">Gerar Prova</button>
                        <a href="lista.php?action=EnviaDadosLista"><input type="button" id="singlebutton" name="btnVoltar" class="btn btn-primary" value="Voltar"/>
                </div>
            </div>
        </form>

PHP:

$id = $_GET['v'];

    $nmodulo = $_POST['txtNmMod'];
    if(isset($_POST['checkPerg']))
    {
        echo "<script>alert('Pera!')</script>";
        if(count($_POST['checkPerg']) > 0)
            foreach($_POST['checkPerg'] as $item)
                echo $item."<br/>";
    }
    if(isset($_POST['txtNrProva']))
    {
        $cdprova = $_POST['txtNrProva'];
    }
    else
    {
        //echo "<script>alert('Pode Voltar!')</script>";
        echo "<meta http-equiv='refresh' content='0, url=lista.php?v=$nmodulo&r=$nrqts&action=GeraLista'>";
    }

Could you help me with this situation?

Thank you in advance.

    
asked by anonymous 20.06.2015 / 18:59

1 answer

3

You are not passing value on your checkbox

echo "<td><input type='checkbox' name='checkPerg[]'/></td><br/>";

Put something like this:

echo "<td><input type='checkbox' name='checkPerg[]' value='sim'/></td><br/>";

or

echo "<td><input type='checkbox' name='checkPerg[]' value='" . $seuValor . "'/></td><br/>";
    
20.06.2015 / 19:09