gpt4 book ai didi

php - 如果多个复选框在 php 中是动态的,如何存储它们

转载 作者:行者123 更新时间:2023-11-29 20:11:29 28 4
gpt4 key购买 nike

您好,我正在尝试将多个选定的值存储在具有上次插入的 ID 的新表中。

enter image description here

my error is array is coming but id_facility value is not coming

这是我的表格:

<ul id="hostel_facility" class="dropdown-menu dropdown-select">
<?php $facility = $conn->query("SELECT * FROM os_facilities ORDER BY id_facility ASC");
while ($facilityresult = $facility->fetch_assoc()) { ?>
<li><a><input type="checkbox" name="hostel_facility[]" value="<?php echo$facilityresult['id_facility']; ?>" /><?php echo $facilityresult['facility_name']; ?></a></li>
<?php } ?>
</ul>

我想存储在新表中的列是 id_hostel、id_facility

最佳答案

我的表格:

<ul id="hostel_facility" class="dropdown-menu dropdown-select">
<?php $facility = $conn->query("SELECT * FROM os_facilities ORDER BY id_facility ASC");
while ($facilityresult = $facility->fetch_assoc()) { ?>
<li><a><input type="checkbox" name="hostel_facility[]" value="<?php echo $facilityresult['id_facility']; ?>" /><?php echo $facilityresult['facility_name']; ?></a></li>
<?php } ?>
</ul>

这是存储作业后我的 Controller 页面:

$hostelId=$conn->insert_id;
if($addHostel)
{
foreach($hostelData['hostel_facility'] as $key=>$facility)
{
$conn->query("INSERT INTO os_hostel_facility (id_hostel,id_facility) values ('".$hostelId."','".$facility."')");
}

关于php - 如果多个复选框在 php 中是动态的,如何存储它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080283/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com