Pass the GET variable over more than one page

Asked

Viewed 1,269 times

0

Step two variables via GET to a page with a PHP condition, where I extract a new variable that I must send to a second page, but for this second page should go the 3 variables but is sending only the last.

Follow the best explained code.

<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>
  • Hello, you are not writing $Loc or $ori in the "select option", only in the SQL query, so clicking the button will not act on them. If you want to save these two variables and send one more per GET by clicking the button, add the variables in the "select option" or save them in SESSION

  • In order to send together with the form, you need to place them in form fields, they can be hidden, for example try to use two fields hidden inside your <form>: <input name=loc type=hidden value="<?php echo $_GET['loc'];?>" and <input name=ori type=hidden value="<?php echo $_GET['ori'];?>" and rescue them with GET

  • 1

    @Pauloroberto, In your way it worked, thank you very much!

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 the page real_time.qm.php redeem the values passed via GET

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

You could also attach the recovered values via GET in the form action and send the select value 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'];
  • Lacked functional "example" euhaeuh :D

  • @When ready, your request has been granted, huauhuahuah

  • :D and this time in double dose rs

1

USING SESSION

At the beginning of the PHP file add

session_start();

Create an array with $Loc and $ori and save to SESSION:

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

On the page where you want to recover the 3 variables you start the session, give a GET or POST in the "name" of select and retrieves 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
  • Jhonatan, the mysqli was not depreciated, it was the mysql_, without i, read this: Why should we not use mysql type functions_?*. Another thing, depreciated is not the correct term, in fact it is a common mistake for programmers to associate the English word that has a different meaning, read this: What is a deprecated code?

  • Oh yes, fault my kk Thanks for the remark.

  • I recommend that you change the code back to mysqli, because there is no need for the author to use PDO, it already started in mysqli same.

  • I don’t understand what that name is for in the option

  • To get the value of the option in PHP... $_GET['nameDoOption'];

  • There must be several options because they are generated within a while. Wouldn’t it be taking the option value by the select name? $_GET['paper'];

  • Oops, truth, confusion. select takes "name" and "option" takes "value"

Show 2 more comments

Browser other questions tagged

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