Database Search with select value

3

How do I perform a search in the database, through a parameter reported by the tag select ?

Follow the code below:

   <select  class="form-control" id="inputUnidade">
     <option>Selecione</option>
     <option>*GCOI</option>
     <option>ESC - RJ</option>
  </select>

Example, if you choose "ESC-RJ", search only the records that are "ESC-RJ". Any tips?

    
asked by anonymous 28.01.2016 / 12:34

2 answers

5

HTML

 <select  class="form-control" id="inputUnidade" name="inputUnidade">
       <option>Selecione</option>
       <option>*GCOI</option>
       <option>ESC - RJ</option>
 </select>

PHP

 <?php
      $unidade = $_POST['inputUnidade'];

      $sql = "SELECT * FROM Tabela WHERE Unidade = '$unidade'";
    
28.01.2016 / 12:42
0

The problem with your code is that your options , are incomplete:

<select  class="form-control" id="inputUnidade" name="inputUnidade">
    <option value="{valor que sera atribuido ao select}">{alias}</option>
</select>

It must have the value attribute so that select has the value selected.

So:

<select  class="form-control" id="inputUnidade">
    <option value="">Selecione</option>
    <option value="*GCOI">*GCOI</option>
    <option value="ESC - RJ">ESC - RJ</option>
</select>
    
28.01.2016 / 13:35