Problem showing what you extract with $ _POST (Input)

0

Good afternoon!

I'm making an order form.

This select, I get the design of the BIFOCALES family We say that you save the ID of the design, so that it can be hooked later with the ID (If or if I have to work with the IDs)

 <select name="bif_oi" onchange="this.form.submit()">
  <option value="0" disabled selected>Seleccione diseño </opcion>
       <?php
              /* creamos la consulta */
              $result=mysqli_query($link, "SELECT * FROM disenyos where id_familia = 8;");

              /* utilizamos un ciclo repetitivo para obtener los datos de la tabla */            

              while ($valores = mysqli_fetch_array($result)) {

                  /* preguntamos si es el seleccionado por el usuario */
                  if (isset($_POST['bif_oi'])){

                  if($valores['id_disenyo']==$_POST['bif_oi']){
                  ?>

                  <!-- Llenamos el select con lo seleccionado por el usuario -->
                  <!-- Agrego el id del diseño como valor del campo -->
                  <option value="<?php echo $valores['id_disenyo'] ?>"selected> <?php echo $valores['nombre']; ?> </option>

                 <?php 
                   }

                  else {
                       ?>
                 <!-- Llenamos el select con los datos de la tabla -->
                 <!-- Agrego el id del diseño como valor del campo -->
                 <option value="<?php echo $valores['id_disenyo'] ?>"> <?php echo $valores['nombre']; ?> </option>   
                 <?php                    
                      } /* cierre del else $valores*/ 
                   } /* cierre del if del isset */

                  else {
                 ?>
                  <!-- Llenamos el select con los datos de la tabla -->
                  <!-- Agrego el id del diseño como valor del campo -->
                  <option value="<?php echo $valores['id_disenyo'] ?>"> <?php echo $valores['nombre']; ?> </option>   
                  <?php                    
                              } /* cierre del else del isset*/
                  } /* cierre del while */
                  ?>
      </select>

The problem, that when you put this in the INPUT, you do not get the name, you get the value from the ID  How can I make it show the NAME, and not the ID?

Inside this input:

<input type="text" name="lenteoi" value="<?php echo $_POST["bif_oi"]; ?>"/>

I would greatly appreciate some kind of solution or proposal. Thank you very much and greetings! :)

    
asked by Javier Avila Fernandez 19.12.2017 в 17:22
source

1 answer

0

What happens is that you are setting the value of the option, the ID

<option value="<?php echo $valores['id_disenyo'] ?>"selected> <?php echo $valores['nombre']; ?> </option>

And that later is translated to

<input type="text" name="lenteoi" value="<?php echo **$_POST["bif_oi"]**; ?>"/>

To put the name, and not the ID, you have to put the following value in option

<option value="<?php echo $valores['nombre'] ?>"selected> <?php echo $valores['nombre']; ?> </option>

On the side, all the options are being set as selected, and that's a mistake ... there should only be one option with selected.

    
answered by 19.12.2017 в 19:52