I am currently developing a web application. I need to insert checkbox values into one table column names as breakfast. When I run the code data are inserted fine. but it display error message on the page as, Undefined index: breakfast and implode(): Invalid arguments passed. Here is my php code;
'<?php
$checkBox = implode(",", $_POST['breakfast']);
if(isset($_POST['add'])) {
$query1="INSERT INTO dietplans (breakfast) VALUES ('" . $checkBox . "') ";
mysqli_query($db,$query1);
}
?>'
Here is the HTML code;
<h4><b>Breakfast(8.a.m.)</b></h4>
<div class="form-check">
<input type="checkbox" value="Full-fat milk 1 cup" name="breakfast[]">
<label>Full-fat milk 1 cup</label>
</div>
<div class="form-check">
<input type="checkbox" value="2 thin slices of bread with margerine " name="breakfast[]">
<label>2 thin slices of bread with margerine </label>
</div>
<div class="form-check">
<input type="checkbox" value="2 medium size bananas " name="breakfast[]">
<label>2 medium size bananas</label>
</div>
<button type="submit" name="add" class="btn btn-dark ">Add my breakfast</button