0
votes

I nedd help. I have form with 5 checkboxes and I need these values (when someone mark it) into one cell in database. Right now when you chceck some checkboxes, always send only value of last checkbox in code.

HTML:

<label class="dieta"><input type="checkbox" name="dieta[]" value="Vegertarian">Vegetarian</label>
<label class="dieta"><input type="checkbox" name="dieta[]" value="Vegan">Vegan</label>
<label class="dieta"><input type="checkbox" name="dieta[]" value="Bezlepku">Bez lepku</label>
<label class="dieta"><input type="checkbox" name="dieta[]" value="Bezlaktozy">Bez laktózy</label>
<label class="dieta"><input type="checkbox" name="dieta[]" value="Hindu">Hindu</label>

(Bad code) PHP:

$dieta = $_POST['dieta'];
require_once 'pripoj.php';
mysqli_query ($link, "INSERT INTO `d156881_tomas`.`svatba` (`dieta`,  `ID`) VALUES ('$dieta', NULL);");

Thanks so much if you let me know how to do.

1

1 Answers

0
votes

In your PHP file.

$dieta = $_POST['dieta'];

$dieta is not a single valued variable.It is collection of values under the single name called Array.So need to use loop.Like this..

foreach($dieta as $d){
mysqli_query ($link, "INSERT INTO d156881_tomas.svatba (dieta, ID) VALUES ('$d', NULL)");
}