How to submit via the PHP form, the selected option of an HTML5 select/option?

Asked

Viewed 267 times

1

inserir a descrição da imagem aquiinserir a descrição da imagem aqui

The function Obtem_Todas_Meta returns to query of the bank, I associate obtain the id that need and send by form, but the value I selected is not sent correctly, as it ends up sending the last value and the times of the first of the list option.

<select  name="opcaometa">
    <?php 
    $dados = Obtem_Todas_Meta();                  
    while ($resultado = mysqli_fetch_array($dados)){    ?>      
        <option  value="3"><?php echo $resultado['id_met']."-".$resultado['titulo_met']; ?>
        </option>
    <?php }?>
</select>
  • the field is id_met?

  • that the field I want to send is id_met to register in the bank

  • i still thought about sending through a session //$_SESSION['id_da_meta'] = $result['id_met']; but still sends the wrong value

  • <select name='opcaometa'> <option value='Advanced PHP Course' name='Advanced PHP Course>Advanced PHP Course</option> </select>, if your select is being generated dynamically in this way, no Hamilton blems will occur. If it still doesn’t work there is problem elsewhere in the code.

  • @Hamiltonventura edited the question making the code easier to read and realized that in PHP within the option there are an quotes missing in ."-.. Please check your original code to see if it exists.

  • yes there is, it was probably time for me to edit the code to send it got like this

  • give a look updated with a database image , I selected the number 15 as ID in the option and it sent 14 -

  • <option value="" here is a problem?

  • I am testing here I have already updated put a value 3. The value that the option sends is always the one of the first item in the list.

Show 4 more comments

1 answer

0


You can’t cross the field value blank or with a fixed value, you have to pass the information you want on the other page (id or name):

Example:

<option value="'.$resultado['id_met'].'">'.$resultado['id_met']."-".$resultado['titulo_met'];.'</option
  • Thanks worked out that was right, I also had problem in the database function. Valew

  • Okay! If it helped you accept the answer :)

Browser other questions tagged

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