【发布时间】:2021-04-03 16:50:49
【问题描述】:
我目前正在开发一个网络应用程序。我需要将复选框值插入到一个表列名称中作为早餐。当我运行代码数据时插入正常。但它在页面上显示错误消息,未定义索引:早餐和内爆():传递的参数无效。这是我的php代码;
'
$checkBox = implode(",", $_POST['breakfast']);
if(isset($_POST['add'])) {
$query1="INSERT INTO dietplans (breakfast) VALUES ('" . $checkBox . "') ";
mysqli_query($db,$query1);
}
?>'
这是 HTML 代码;
<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
【问题讨论】:
标签: php