Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

jQuery update with checkbox to update db doesnt work

Featured Replies

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

Edited by chrishutagalung

  • 1 month later...

First things first, Get FireBug installed on firefox and watch the AJAX call to check the response (you might get an error to debug that way)

 

Second, do youself a favour use PDO or wrap those $_POST variblaes with mysql_real_escape_string() before using them in your queries, someone could SQL Inject the living crap out of that.

 

T

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.