Pass the GET variable by more than one page

0

Here is the code that is best explained.

<form class="got" method="GET" action="real_time.qm.php">
                <select name="papel">
<?php
//Recebo as variaveis da outra pagina
$loc = $_GET['loc'];
$ori = $_GET['ori'];

include ("Conectcma.php");

        $pl = "SELECT Papel FROM reg_qm_papel WHERE Local = '$loc' AND origem = '$ori'";
        $plgo = mysqli_query($conexao, $pl);

    while($sc_l = mysqli_fetch_array($plgo)){
       echo '<option>'.$sc_l['Papel'].'</option>';
   }
?>
</select>
<br>
     <br>
     <br>
     <!-- Ao clicar no botão, deveria retornar as 3 variaveis($_GET['loc'],$_GET['ori'] e papel) porém, só retorna a ultima -->
   <button class="css_btn_class" type="submit"> Acessar Papel  - QM 
   </button>
            </form>
    
asked by anonymous 06.12.2017 / 19:06

2 answers

2

Add two hidden inputs to your form with the values received via GET from the other page

<input type="hidden" name="loc" value="<?php echo $loc ?>">
<input type="hidden" name="ori" value="<?php echo $ori ?>">

Form Page

<form class="got" method="GET" action="real_time.qm.php">
   <select name="papel">
<?php
  //Recebo as variaveis da outra pagina
  $loc = $_GET['loc'];
  $ori = $_GET['ori'];

  include ("Conectcma.php");

    $pl = "SELECT Papel FROM reg_qm_papel WHERE Local = '$loc' AND origem = '$ori'";
    $plgo = mysqli_query($conexao, $pl);

    while($sc_l = mysqli_fetch_array($plgo)){
      echo '<option>'.$sc_l['Papel'].'</option>';
    }
?>
</select>

<input type="hidden" name="loc" value="<?php echo $loc ?>">
<input type="hidden" name="ori" value="<?php echo $ori ?>">

 <br>
 <br>
 <br>
 <button class="css_btn_class" type="submit"> Acessar Papel  - QM</button>
</form>

On page real_time.qm.php retrieve values passed via GET

$loc = $_GET['loc'];
$ori = $_GET['ori'];
$papel = $_GET['papel'];
  

I could also attach the values retrieved via GET in the form action and send the value of the select via POST:

<form class="got" method="POST" action="real_time.qm.php?loc=<?php echo $_GET['loc'] ?>&ori=<?php echo $_GET['ori'] ?>">

page real_time.qm.php

$loc = $_GET['loc'];
$ori = $_GET['ori'];
$papel = $_POST['papel'];
    
07.12.2017 / 00:34
0

USING SESSION

At the beginning of the PHP file add

session_start();

Create a vector with $ loc and $ ori and save in SESSION:

$dados = array(
    "local" => $loc,
    "origem" => $ori
);
$_SESSION["localOrigem"] = $dados;

On the page where you want to retrieve the 3 variables, you can start the session by either GET or POST in the select name and retrieve the session vector:

session_start();
$doFormulario = $_GET["name_do_select"]; //coloque o nome do select
$variaveis_loc_e_ori = $_SESSION["localOrigem"];
//pronto, a variável do form está em cima e a loc e ori em baixo
    
06.12.2017 / 19:39