Hi Folks,

I need help with my code. Basically I am building an inventory progress web so that it pulls the value from the dropbox, and with onChange, getting the corresponding value from the DB, Update the value and reinsert the new value to the DB using submit button. One thing that doesnt work is only the submit button and ive been trying so hard to resolve this kind of issue. PLease help me, any kind of help would be greatly appreciated.

// ASSUME THE CONNECTION IS DONE with $conn

if (isset($_POST["ajax"]) && $_POST["ajax"] == 1){
       $sql = "SELECT QTY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
       $cutting_sql = "SELECT CUTTING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";

       $stid = oci_parse($conn, $sql);
       $stid_cutting = oci_parse($conn, $cutting_sql);

        // The defines MUST be done before executing
        oci_define_by_name($stid, 'QTY', $qty);
        oci_execute($stid);

        oci_define_by_name($stid_cutting, 'CUTTING', $cutting);
        oci_execute($stid_cutting);  

        // Each fetch populates the previously defined variables with the next row's data
        oci_fetch($stid);
        oci_fetch($stid_cutting);


        //echo quantity to the screen
        echo "<b><font size='10'>".$qty."</font></b></br>";
        if ($cutting == $qty){
            echo "<p><b><font color='#FF8566' size='5'>CUTTING COMPLETED</font></b></p>";
        } else {
            $maxcutting = $qty - $cutting;
            echo "<input id='cutting' name='cutting' type='number' min = '0' max = '$maxcutting' placeholder='CUTTING DONE: $cutting' class='input'/>";
        }

        // THIS IS WHERE THE PROBLEM STARTS
        echo '<section></br></br></br>'; 
        echo '       <input type="submit" name="submit" value="SUBMIT PROGRESS" class="button red" />';
        if (isset($_GET['submit'])){

            oci_bind_by_name($statement, $cuttingz, $_POST["cutting"]);
            echo $cuttingz;
            echo '<script type="text/javascript">alert("hello button pressed");</script>'; 
        }
        echo '       <input type="reset"  value="RESET FIELDS"    class="button" /></br>';
        echo '       <input type="button" value="GO TO PAINTING"  name="paint" id="paint" class="button green" /></section>';  

        die;
} //AJAX--Closing--Brace
?>

<!DOCTYPE html>
<html lang="en">
<head>
       <script type="text/javascript">
           function OnSelectionChange (select) {
            var selectedOption = select.options[select.selectedIndex];
            //some ajax checkpoint
            //alert ("The selected option is " + selectedOption.value);          
                        jQuery.ajax({
                                url: location.href,
                                data: {'hm':selectedOption.value, 'ajax':1},
                                type: "POST",
                                success: function( data ) {
                                        jQuery("#lbl_qty").html(data);//PRINT QTY TO THE SCREEN
                                }                           
                        });
                        //some ajax checkpoint
                        //alert('after ajax');
            }

       </script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
</head>
</body>

                                        <!-- POPULATED DROPDOWN LIST FROM THE DB -->
                                        <label for="headmark" class="lbl-ui select">
                                            <?php         
                                             $sql_hm_comp = 'SELECT HEAD_MARK FROM FABRICATION';

                                            $result = oci_parse($conn, $sql_hm_comp);
                                            oci_execute($result);

                                            echo '<SELECT name="headmark" id="headmark" onchange="OnSelectionChange(this)">'.'<br>';
                                            echo '<OPTION VALUE=" ">'."".'</OPTION>';

                                            while($row = oci_fetch_array($result,OCI_ASSOC)){
                                                 $HM = $row ['HEAD_MARK'];
                                                 echo "<OPTION VALUE='$HM'>$HM</OPTION>";
                                            }
                                            echo '</SELECT>';
                                        ?>
                                        </label>     
                                    </div>   
                                </div>                        
                           </section><!-- END OF DROPDOWN LIST -->                                              
                          <section>
                                <div class="row">
                                    <div class="col4 first">
                                        <label for="lnames" class="lbl-text tleft">Total Quantity:</label>
                                    </div>
                                    <div class="col8 last">
                                    <!-- VALUE PASSED FROM AJAX PROCESSING -->
                                    <label id='lbl_qty' class='lbl-ui'><font size='3'></font></label>               
                                    </div>   
                                </div>                        
                           </section> 
            </form>
</body>
</html>

Dani AI

Generated

As noted, the symptom matches several common issues: a missing or misplaced form opening tag, a submit button that exists only inside an AJAX response (so it’s not actually part of a real form), mixed/mismatched request methods (checking $_GET when submission is POST), and server-side code that references undefined variables (for example an update statement/handle never prepared before oci_bind_by_name). The quickest checks are: confirm a proper <form method="post" action="..."> wraps the inputs, ensure the submit control has a name, and switch any server-side checks to look for POST data or an explicit action flag.

Recommended approaches (pick one that fits the flow):

  • Keep the submit button as part of the main page form (not only inside the AJAX response). Use the AJAX call to return data (JSON or small HTML snippets) and populate existing inputs inside that form. That way a normal submit will post all fields to the server.
  • Or handle the submit entirely via AJAX: add an id/name to the generated button and use event delegation so clicks on dynamically inserted controls are handled.

Example patterns (do not copy into production without adapting):

<form id="progressForm" method="post" action="">
  <input type="hidden" name="hm" id="hm" value="">
  <input type="number" id="cutting" name="cutting" min="0">
  <input type="submit" id="submit_progress" name="save_progress" value="SUBMIT PROGRESS">
</form>
$(document).on('submit', '#progressForm', function(e){
  e.preventDefault();
  var payload = $(this).serialize() + '&ajax_save=1';
  $.post(location.href, payload, function(resp){
    // handle JSON response: show success / update UI
  }, 'json');
});

Server-side: check the request method and the action flag, prepare a proper UPDATE with oci_parse, bind variables with oci_bind_by_name, then oci_execute and return JSON. Also enable error reporting during debugging:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Troubleshooting checklist: confirm the DOM contains the form and inputs (use Elements inspector), watch the Network tab for the POST payload and response, check PHP warnings/notices for undefined variables (like $statement), and use console.log or alerts to verify event handlers fire. These steps address the structural causes that prevent the submit from ever reaching the server.

Is that HTML a complete copy of the code you are using?
You have a body end tag instead of a body opening tag, and I cannot see the form opening tag, only the form end tag.
If you change the button from a 'submit' to a 'button', just for testing, does it trigger your event handler?
The 'submit' works on a form, causing a submit to the server, so not having the form opening tag will be an issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.