dimanche 26 février 2017

Values from checked checkboxes insert into database

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.




Aucun commentaire:

Enregistrer un commentaire