Tim Tim - 2 years ago 99
HTML Question

Using POST to get select option value from HTML form

I have a form where i get some different information. But then i have a Select with multiple options and i want to be able to send this to the database in 1 or 0 / true or false. But it is not working. This is my code so far:

<select multiple>
<option value="" disabled selected>Choose your option</option>
<option name="esea" value="1">ESEA</option>
<option name="faceit" value="1">FaceIT</option>
<option name="matchmaking" value="1">Matchmaking</option>
<label>What are you looking to play?</label>

And this is my php:

$sql = "INSERT INTO users
( profilename, profileurl, avatar, region,
age, esea, faceit, matchmaking, textarea1 )


$insert = $mysqli->query($sql);

I know that this code doesnt work but i don't know what to do to make it work. I wan't to send a 1 or a 0 depending on if the chose the alternative or not.

Answer Source

Your <select> for a multiple selectable dropdown needs to be an array, defined by name="enterNameThatMakesSense[]"

<select name="enterNameThatMakesSense[]" multiple>

And then processed like this in PHP, for example

foreach ( $_POST['enterNameThatMakesSense'] as $val) {
    echo $val;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download