mercredi 11 juillet 2018

foreach in PHP - how to transfer the values in a variable?

so the problem is, I have a HTML form with checkboxes as an input-option. I want to save all the selected options as a string(!) in one variable.

I'm pretty sure the solution is a foreach-loop, but mine doesn't work. It only returns the last selected value.

How can I fix this?

HTML

<form action="" method="post">
<label>category:<br/>
     one <input type="checkbox" name ="ber[]" value="one"><br/>
     two <input type="checkbox" name ="ber[]" value="two"><br/>
     thr <input type="checkbox" name ="ber[]" value="three"><br/>
     fou <input type="checkbox" name ="ber[]" value="four"><br/>
</form>

PHP

foreach ($_POST['ber'] as $value) {
$ber = "$value. ', '"
}




Aucun commentaire:

Enregistrer un commentaire