Take option value and save to a variable to register in the bank

Asked

Viewed 178 times

-2

<p>Escolha a categoria:
        <select name="categoria">
        <option></option>
        <option value="v1">Conhecimentos gerais</option>
        <option value="v2">Português</option>
        <option value="v3">Matemática</option>
        <option value="v4">História</option>
        <option value="v5">Geografia</option>
        <option value="v6">Sociologia</option>
        <option value="v7">Tecnologia</option>
        <option value="v8">Biologia</option>
        <option value="v9">Programação</option>
        <option value="v10">Banco de dados</option>
        </select>

2 answers

0


If you use GET -> $category = $_GET['category'];

If you use POST --> $category = $_POST['category'];

The value of the selected option will be sent and the option value will be stored in the category variable, which can be transported to insert the information in the database.

0

<p>Escolha a categoria:</p>

    <select name="categoria">
       <option value="v1">Conhecimentos gerais</option>
       <option value="v2">Português</option>
       <option value="v3">Matemática</option>
    </select>

    <?php  
       $var = $_POST['categoria'];
       //  ou $_GET
    ?>

The value of the parameter category that’s coming through POST, just as mentioned by dear Wellson Almeida, will be stored in the variable $var and so you can use this $var and send it to your bank.

A tip: You can filter this parameter data through an array, for example:

instead of using -> name="category" use name="category[]"
this returns an array and from there you can browse this array with a foreach for example...

Browser other questions tagged

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