pass two parameters via GET

Asked

Viewed 2,147 times

-1

Hello, I am doubtful how I can pass 2 parameter via GET, only the second would be after the answer of the first. what I want to do is select an item in an input select and update the page with that parameter in GET and then based on this parameter will enable an input text field for me to type something that will query the 2 parameters together in the WHERE clause.

my current code:

if ( isset($_GET["revenda"])  ) {
$var1 = $_GET["revenda"];

$query = ("SELECT bem, des_bem, revenda FROM AFX_BEM WHERE revenda LIKE :imobilizado "); 
$stmt = $pdo->prepare($query);
$stmt->bindValue(':imobilizado', '%' . $var1 . '%', PDO::PARAM_STR);
$stmt->execute();

}

if ( isset($_GET["bemdesc"])  ) {
$var1 = $_GET["revenda"];
$var2 = $_GET["bemdesc"];

$query = ("SELECT bem, des_bem, revenda FROM AFX_BEM WHERE revenda LIKE :rev AND des_bem LIKE :bd "); 
$stmt2 = $pdo->prepare($query);
$stmt2->bindValue(':rev', '%' . $var1 . '%', PDO::PARAM_STR);
$stmt2->bindValue(':bd', '%' . $var2 . '%', PDO::PARAM_STR);
$stmt2->execute();

}

<form class="form-inline" role="form" action="lista.php" method="get">
         <div class="form-group">
             <label for="revenda">Pesquisar</label>      

             <select class="form-control" name="revenda" style="width: 140px" onchange="this.form.submit();" >
                       <option value="" disabled selected><?php if(isset($_GET["revenda"]) ) { 
                       if ( ($_GET["revenda"]) == 1 ) { echo "Piracicaba"; }
                       if ( ($_GET["revenda"]) == 2 ) { echo "Botucatu"; }
                       if ( ($_GET["revenda"]) == 3 ) { echo "São Manuel"; }
                       if ( ($_GET["revenda"]) == 4 ) { echo "Lençóis Paulista"; }
                       if ( ($_GET["revenda"]) == 5 ) { echo "Jaú"; }
                       if ( ($_GET["revenda"]) == 6 ) { echo "Ibitinga"; }



                       } else {  ?>Revenda <?php } ?></option>
                        <?php
                            $linha2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
                            foreach($linha2 as $listar2){



                        ?>
                        <option value="<?php echo $listar2["REVENDA"]; ?>">
                            <?php echo utf8_encode($listar2["RAZAO_SOCIAL"]);    ?>
                        </option>


                        <?php
                            }

                        ?>

                        </select>



            <?php if(isset($_GET["revenda"]) ) {
                $bemdesc = "teste";
            ?>

            <form action="lista.php?revenda='<?php echo $revenda ?>' " method="get">
             <input class="form-control" type="text" name="bemdesc" id="bemdesc" placeholder="BEM ou Descrição">
             <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>

            <?php
            }
            ?>
             </form>


         </div>
     </form>insira o código aqui
  • You’re trying to send two <form> with the same submit? That’s what you’re trying to do?

  • even closing a </form> on top of the other qdo I type something in the second and Submit the first parameter some of the url and only the new one

  • Try to put everything into it form

  • same effect.. url deletes resale=5 (/immobilized/list.php?resale=5) and looks like this: /immobilized/list.php? bemdesc=table .. I need to add resale=5&bemdesc=table

1 answer

0

Place within only 1 <form> thus:

<form class="form-inline" role="form" action="lista.php" method="get">
<input type="text" name="texto1" value="textoDigitado1">
<input type="text" name="texto2" value="textoDigitado2">
<button type="submit"></button></form>

That way the url result would look like this:

lista.php?texto1=textoDigitado1&texto2=textoDigitado2
  • I need to submit the value of select first.. then my url will be 1 get.. after this will open an input field for me to submit a second get of type text

Browser other questions tagged

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