Variable pass problem in PHP

Asked

Viewed 42 times

1

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

Follow code of the form:

<?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>

    <div id="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>    

Follow code from 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>
  • "My code is not receiving the value of the variable at the time it is passed by GET / POST" - Which variable ? Would that be $_POST["insert"] to which you refer ?

  • What is the reason to use POST and GET together? I think you could submit it all by POST

  • $passacod=$_GET["passcode"];

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.