Show selected combobox option with PHP

0

I have the following code which fills me a combobox with options brought from a database:

<?php

    $conexion = mysqli_connect("localhost" , "root" , "");
    $bd = mysqli_select_db ($conexion, "empresa");

    $destinos = mysqli_query($conexion, "SELECT nombre FROM destinos");


    echo ("<form action='destino.php' method='POST'>");
echo ("<select name='destinos'>");
while ($dest = mysqli_fetch_array($destinos)) {
    echo "<option value='".$dest['id']."'>".$dest['nombre']."</option>";
}
echo ("</select>");
echo ("<br><br>");
echo ("<input type='submit' value='Buscar'>");
echo ("</form>");


    ?>

And I need to show the option selected in "destino.php". I have the following code in destino.php:

<?php
  if(isset($_POST['submit'])) {

     foreach ($_POST['destinos'] as $select)
     {
       echo $select;
     }
   }
?>

Which like this:

<?php

$destino = $_POST['destinos'];

echo ("Has seleccionado: ".$destino);


?>

He does not show me anything. It does not throw me error or anything like that, but it does not return the selected option.

    
asked by Lucas. D 14.06.2017 в 01:39
source

0 answers