POST does not obtain normal field value but if generated dynamically

0

I have these two fields of select, the first article to change fills the 2nd.

By doing POST only saves the values of section (this generated dynamically) but the article does not save.

ListArticle:

function listaArticulos()
      {
      global $conexion;
      $stmt = $conexion->prepare("SELECT numero_articulo FROM articulos");
      $stmt->execute();
      $stmt->store_result();
      $stmt->bind_result($stmt1);
      while ($stmt->fetch())
            {
            echo "<option value=" . $stmt1 . ">" . $stmt1 . "</option>";
            }
      $stmt->close();
      }

HTML
                       Select the inflicted item:                                    Select an article:                        

       <select id="apartado" onchange="obtenerDesc()" name="apartado">
       <option value="0">Seleccione primero un art&iacute;culo</option>
       </select>
       </td>
       </tr>

POST:

<?php
$articulo_falta = $_POST["articulo"];
echo $articulo;
$aparte_falta = $_POST["apartado"];
echo $aparte_falta;
?>

Result:

  

Undefined variable: article

     

4

    
asked by Victor Alvarado 10.03.2017 в 16:16
source

2 answers

2

Your variables are called different. Instead of

$articulo_falta = $_POST["articulo"];
echo $articulo;

should be

$articulo_falta = $_POST["articulo"];
echo $articulo_falta;
    
answered by 10.03.2017 / 16:19
source
0

Your SELECT inputs need to have a different name or be an array; they are only showing how you generate a SELECT , if the second one has the same name then it overwrites the variable in POST when you get to PHP.

You can generate your inputs like this:

<SELECT name="mi_nombre[]"><option>1</option>

In this case $_POST["articulo"][0] would have a value and $_POST["articulo"][1] other.

    
answered by 10.03.2017 в 22:46