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.
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)");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.