I would like to save multiple checkbox(PHP and JQuery) in to MYSQL database. Example table test there are 4 fields. Column A, NAME, C AND D.
After I clicked save it will be saved to those table;
jQuery code:
$(document).ready(function() {
$("#btnsave").click(function() {
var test = [];
$("input[name='aa[]']:checked").each(function() {
test.push($(this).val());
});
alert(test);
});
});
function toggleCheckeda(status) {
$(".chkaa").each( function() {
$(this).attr("checked", status);
})
}
function toggleCheckedb(status) {
$(".chkab").each( function() {
$(this).attr("checked", status);
})
}
function toggleCheckedc(status) {
$(".chkac").each( function() {
$(this).attr("checked",status);
})
}
PHP code:
$db->Connect();
$stmt = $db->ExecData("select id,A,name,C,D from tbl_check");
<form id="frm1" name="frm1">
<table>
<tr>
<td>
<input type="checkbox" value="" onclick="toggleCheckeda(this.checked)">
</td>
<td></td>
<td>
<input type="checkbox" value="" onclick="toggleCheckedb(this.checked)">
</td>
<td>
<input type="checkbox" value="" onclick="toggleCheckedc(this.checked)">
</td>
</tr>
<tr>
<th>
A
</th>
<th>
Name
</th>
<th>
C
</th>
<th>
D
</th>
</tr>
<?php while ($row = $db->GetRow($stmt)){ ?>
<tr>
<td>
<input type="checkbox" class="chkaa" name="aa[]" id="chk[]" value="a<?php echo $row["id"]; ?>" />
</td>
<td>
<?php echo $row["name"]; ?>
</td>
<td>
<input type="checkbox" class="chkab" name="cc[]" id="chk[]" value="c<?php echo $row["id"]; ?>" />
</td>
<td>
<input type="checkbox" class="chkac" name="dd[]" id="chk[]" value="d<?php echo $row["id"]; ?>" />
</td>
</tr>
<?php } ?>
</table>
<input type="button" id="btnsave" name="btnsave" value="save" />
</form>