Problem submitting form with SELECT tag, empty $_POST array

Asked

Viewed 137 times

0

When submitting the above form, the PHP script shows an error, saying that the index 'estab' is undefined. The function 'var_dump' shows an empty vector.

    <form action="PHP_scripts/gerarApp.php" method="post" onsubmit="return waiting()">
        <select id="estab" name="estab" class="form-control">
            <option value="0">Selecione o estabelecimento</option>
            <?php
            foreach($pdo->query("SELECT numEstabelecimento, nomeEstabelecimento FROM Estabelecimento") as $estab)
                echo '<option value='.$estab['numEstabelecimento'].'>'.htmlentities($estab['nomeEstabelecimento']).'</option>';
            ?>
        </select>

        <input type="submit" id="generateApp" value="Gerar Aplicativo" class="btn btn-lg btn-primary">
    </form>



<?php
var_dump($_POST);
$numEstab = $_POST['estab'];
?>

The curious thing is that I have another page with a form that contains a 'select' field and it works. I don’t understand why this case isn’t working.

Would anyone know where the mistake is? Thank you very much.

1 answer

0

<form action="PHP_scripts/gerarApp.php" method="post" onsubmit="return waiting()">
    <select id="estab" name="estab" class="form-control">
        <option value="0">Selecione o estabelecimento</option>
        <?php
        foreach($pdo->query("SELECT numEstabelecimento, nomeEstabelecimento FROM Estabelecimento") as $estab)
            echo '<option value="'.$estab['numEstabelecimento'].'">'.htmlentities($estab['nomeEstabelecimento']).'</option>';
        ?>
    </select>

    <input type="submit" id="generateApp" value="Gerar Aplicativo" class="btn btn-lg btn-primary">
</form>

Browser other questions tagged

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