I am working on a project that is stuck right now. So the idea is I have the checkboxes generated from the oci_fetch_array() into a table and when user check the checkbox, it automatically updates the database with corresponding data and disable the checkbox. My code is as follows, This is the jQuery
$('.cuttingCheckbox').change(function() {
if (this.checked) {
var $this = $(this);
$.post('process_class.php',{
headmark : $(this).data('data-headmark'),
headmark_id : $(this).data('data-id')
}, function(response){
this.setAttribute("disabled", true),
alert(headmark,headmark_id);
});
}
});
and on the same file, the php
<?php
// IF SHOW KEY HAS BEEN PRESSED
if($_POST['action'] == 'show')
{
$sql = "SELECT * FROM FABRICATION
WHERE FABRICATION.HEAD_MARK = '{$_POST["hm"]}'";
$query = oci_parse($conn, $sql);
$query_exec = oci_execute($query);
while($row = oci_fetch_assoc($query)){
echo "<input type='hidden' id='headmarkid' value='".$row['HEAD_MARK']."' />";
echo "<input type='hidden' id='rowid' value='".$row['ID']."' />";
echo "<table border='1'>";
echo '<table cellspacing = "0"';
echo '<thead>';
echo '<tr><th>Head Mark/ID</th>
<th>Cutting</th>
</tr></thead>';
echo "<tbody>";
echo "<tr><td><b>$row[HEAD_MARK]/$row[ID]</b></td>";
if ($row['CUTTING'] == 'Y'){
//echo "<td><input type='checkbox' id='cuttingCheckbox' name='cuttingCheckbox' checked='checked' disabled='disabled'/></td>";
echo "<td><img src='../images/fabDone.png' width='30' height='30'></td>";
} else {
echo "<td><input type='checkbox' data-headmark=".$row['HEAD_MARK']." data-id=".$row['ID']." class='cuttingCheckbox' name='cuttingCheckbox'/></td>";
}
echo "</tr>";
echo "</tbody>";
echo "<table cellspacing = '0'";
}
echo "</table>";
}//===> END OF 'SHOW'
?>
And on the process_class.php to process the database
<?php
$cuttingUpdateParse = oci_parse($conn,"UPDATE FABRICATION_QC SET CUTTING = 'Y'
WHERE HEAD_MARK = ".$_POST["headmark"]." AND ID = ".$_POST["headmark_id"].";");
$cuttingUpdateRes = oci_execute($cuttingUpdateParse);
if ($cuttingUpdateRes){
oci_commit($conn);
echo "<script>alert('CUTTING UPDATED');</script>";
} else {
echo "<script>alert('CUTTING NOT UPDATED');</script>";
}
?>
So the problem is now i cant make the checkbox to work to update the database. I am sure its something wrong with the jQuery. Can someone help me ? i know my code is kinda messy and pardon me