I want to get values in PHP throughout a html form-ThrowExceptions

Exception or error:

Im new to PHP and want to get these arrays to send by a form, but cant manage to store it in a variable and access them

HTML

<form action="./index.php" method="post">
<select name="multicheckbox[]" multiple="multiple" class="4colactive">
    <option value="LunVie" name="LunVie">Lunes a Viernes</option>
    <option value="LunSab" name="LunSab">Lunes a Sábados</option>
    <option value="Todos" name="Todos">Todos los días</option>
    <option value="Otros" name="Otros">Otros</option>
</select>
<button type="submit">Enviar</button>
</form>

PHP

<?php
  $values = $_POST["multicheckbox"];
  echo $values[2];
?>
How to solve:

multicheckbox is an array, iterate over it.

foreach($_POST["multicheckbox"] as $check) {
    echo $check . "<br />\n";
}

Also note options don’t have names, the select has a name. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

<select name="multicheckbox[]" multiple="multiple" class="4colactive">
    <option value="LunVie">Lunes a Viernes</option>
    <option value="LunSab">Lunes a Sábados</option>
    <option value="Todos">Todos los días</option>
    <option value="Otros">Otros</option>
</select>

Leave a Reply

Your email address will not be published. Required fields are marked *