【发布时间】:2026-01-31 15:15:01
【问题描述】:
This is my database
<?php
if(isset($_POST["insert"]))
{
$conn = mysqli_connect("localhost", "root", "", "databaseappfeature");
if(isset($_POST["insert"]) == "1"){
$query = "UPDATE appfeature SET feature_switch = ('".$_POST["insert"]."')";
$result = mysqli_query($conn, $query);
echo "Data Inserted Successfully!";
}
}
?>
This is my javascript code
<script>
$(document).ready(function(){
$('#submit').click(function(){
var insert = [];
$('.get_value').each(function(){
if($(this).is(":checked"))
{
insert.push($(this).val());
}
});
insert = insert.toString();
$.ajax({
url: "insert.php",
method: "POST",
data:{insert:insert},
success:function(data){
$('#result').html(data);
}
});
});
});
</script>
This is my checkbox code
<form action="" method="POST">
<h4 id="result"></h4>
<div class="container">
<h2 align="center">Table App Feature</h2>
<table id="appFeature" class="table table-hover" align="center" style="width:500px;margin:auto;">
<thead>
<tr>
<th>Firstname</th>
<th>Please check to enable the features</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smarthome</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Intercom</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Visitors</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Booking</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Access</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Parcel</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Bills</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Invoices</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
<tr>
<td>Receipts</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Transactions</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Meeting</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
<tr>
<td>Vote</td>
<td>
<input type="checkbox" class="get_value" value="1"/>
</td>
</tr>
<tr>
<td>Feedback</td>
<td>
<input type="checkbox" class="get_value" value="1" />
</td>
</tr>
</tbody>
</table><br />
<div align="center">
<button type="button" name="submit" id="submit">Update</button>
</div>
</div>
</form>
如何将多个复选框的值更新到数据库中,如果选中该复选框,则该值应为 1,如果未选中该复选框,则该值应为 0? This is my checkboxThis is jquery that i use to pass the value of checkboxThis is my database code 请帮助我..我对此很陌生..我正在这样做一个星期..
【问题讨论】:
-
您使用的是哪种服务器端编程语言?如果是 PHP,请查看:*.com/questions/25431334/…
-
您可以从提供最小的工作代码 sn-p 开始,而不是代码片段的图像
-
请不要放屏幕截图的链接。您可以在此处添加您的代码。我们很容易给出答案
-
@vbRocks 我正在使用 php..
标签: javascript arrays database checkbox