I need to write a data chosen by the user, but when all data is not chosen this message appears Notice: Undefined offset: 5 in C: \ xampp \ htdocs \ My projects \ on line 10
I need to write a data chosen by the user, but when all data is not chosen this message appears Notice: Undefined offset: 5 in C: \ xampp \ htdocs \ My projects \ on line 10
Problem
The value of the checkbox not sent to the POST if it is not selected.
Solution
Make sure the value is set in the $ _POST array before using it.
$nro_funcoes = 10;
for ($id = 1; $id <= $nro_funcoes; $id++) {
$nro_funcao[$id] = $id;
}
foreach ($nro_funcao as $func) {
//verificar se está definido
if (isset($_POST[$func])) {
$funcao[$func] = $_POST[$func];
}
}
$dados = implode(', ', array_filter($funcao));