Problem passing variable in PHP

1

My code is not getting the value of the variable at the time it is passed by GET / POST. And so at the time of inserting in the bank, it receives value 0.

Follow form code:

<?php   
header('Content-type: text/html; charset=ISO-8859-1');
?>

<meta charset="utf-8">
<head>
<title>Sistema de Controle de Atas</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
    <script type="text/javascript" src="script4.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script></head><body><divid="cabecalho"> 
        <h2>Sistema de Controle de Atas</h2>
        <div id="logo">
        <img src="logopet.jpg" width="50" height="50" align="">
    </div>


    <div id="ajuda_sair">
    <nav id="menu">
    <ul>
    <li><a href="sistema.php">Sair</a> </li>
    <li><a href="ajuda.html">Ajuda</a> </li>
        <li><a href="telapetiano.php">Voltar ao Menu Principal</a></li>
    <li><strong>Menu do Petiano &nbsp &nbsp </strong></li>

    </ul>
    </nav>
    </div>


    </div>

    <br></br>
    <br></br>


    <h2>Registrar Presenças </h2>


    <div id="grav_presenca">
        <form action="grava_presencas.php" method="POST">

       <?php
        include ("conectarbanco.php");

        $recebecod=$_GET["add_presenca"]; 

        $selecionalinha= mysqli_query($conexao, "SELECT DATE_FORMAT(Data,'%d/%c/%Y') as 'Data',r.CodReuniao from reuniao r where r.CodReuniao=$recebecod");
        $campo= mysqli_fetch_array($selecionalinha);

        ?>

        <input type="hidden" id="CodReuniao" name="CodReuniao" value="<?=$campo["CodReuniao"]?>">
        <label for="data">Data da Reunião:</label>&nbsp &nbsp<input type="text" name="data" size="20" maxlength="10"  readonly="readonly" value="<?=$campo["Data"]?>">


        <h4> Selecione os petianos presentes e ausentes:  </h4>
        <table width="50%" border="1" bordercolor="#EEE" cellspacing="0" cellpadding="10">
        <tr> 
        <td> <strong> Código </strong> </td>
        <td> <strong> Nome</strong> </td>
        <td width="10"><strong>Presentes</strong></td>


        </tr>


       <input type="hidden" name="codPetiano" value="<?=$campo["codPetiano"]?>">

       <?php
       include ("conectarbanco.php");


       $seleciona= mysqli_query($conexao,"SELECT * FROM petianos order by nome ASC");

       while($campo= mysqli_fetch_array($seleciona)){ ?>
       <tr>
       <td><?=$campo["codPetiano"]?></td>
       <td><?=$campo["nome"]?></td> 
       <td><input type="checkbox" class="get_value" value="<?=$campo["nome"]?>"><label></label></td>
       </tr>

       <?php }   ?>

        </table>
        <br></br>



        <?php
        include ("conectarbanco.php");
        $recebecod=$_GET["add_presenca"]; 

        $sel_itens4= mysqli_query($conexao,"SELECT r.CodReuniao FROM reuniao r WHERE CodReuniao=$recebecod");
        while($campo= mysqli_fetch_array($sel_itens4)){ ?>
        <tr>

            <td><a href="grava_presencas.php?passacodigo=<?=$campo["CodReuniao"]?>"><button type="button" name="submit" id="submit">Salvar Chamada</button></a></td>    

        </tr> 



        <?php } ?>

        </table>

        <br></br>   
       <h4 id="result"></h4>
       <script>
       $(document).ready(function(){
       $('#submit').click(function(){
           var insert = [];
       $('.get_value').each(function(){
           if($(this).is(":checked"))
           {
           insert.push($(this).val());
           }
        });
       insert = insert.toString();
       $.ajax({
             url: "grava_presencas.php",
             method: "POST",
             data:{insert:insert},
             success:function(data){
               $('#result').html(data);
       }
       });
       }); 
       });
       </script>




    </form> 
    </div>    

Here is the code for the recording:

<?php

header('Content-type: text/html; charset=ISO-8859-1');
?>
<?php


if (isset($_POST["insert"])) {

    include ("conectarbanco.php");   

    $passacod=$_GET["passacodigo"];

    $query = "INSERT INTO chamada(IdChamada,CodReuniao,nome,statusparticipante) values ('','$passacod','" . $_POST["insert"] . "','presente')";
    $result = mysqli_query($conexao, $query);


}
    echo "<script language='javascript' type='text/javascript'>
    alert('Presenças e Ausências Registradas!');
    window.location.href='reg_presencas.php';
    </script>";

?>    
</body>
</html>
    
asked by anonymous 14.11.2018 / 02:21

0 answers