提交按钮不起作用

时间:2014-03-28 08:06:36

标签: php ajax oracle

我有这段代码,我无法让提交按钮正常工作 请帮我。我准备了3个按钮,我尚未对此动作。但即使我想回应一些东西,该按钮也不起作用

<?php

require_once '../dbinfo.inc.php';
session_start();

// CHECK IF THE USER IS LOGGED ON ACCORDING
// TO THE APPLICATION AUTHENTICATION

if(!isset($_SESSION['username'])){
   echo <<< EOD
   <h1>You are UNAUTHORIZED !</h1>
   <p>INVALID usernames/passwords<p>
   <p><a href="../login.php">LOGIN PAGE</a><p>
EOD;
   exit;
}
// GENERATE THE APPLICATION PAGE
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

// 1. SET THE CLIENT IDENTIFIER AFTER EVERY CALL
// 2. USING UNIQUE VALUE FOR BACK END USER
oci_set_client_identifier($conn, $_SESSION['username']);
$username = htmlentities($_SESSION['username'], ENT_QUOTES);


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"]}'";
   $assembly_sql = "SELECT ASSEMBLY FROM FABRICATION WHERE HEAD_MARK =     '{$_POST["hm"]}'";
   $welding_sql = "SELECT WELDING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
   $drilling_sql = "SELECT DRILLING FROM FABRICATION WHERE HEAD_MARK =  '{$_POST["hm"]}'";
   $finishing_sql = "SELECT FINISHING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";

   $stid = oci_parse($conn, $sql);
   $stid_cutting = oci_parse($conn, $cutting_sql);
   $stid_assembly = oci_parse($conn, $assembly_sql);
   $stid_welding = oci_parse($conn, $welding_sql);
   $stid_drilling = oci_parse($conn, $drilling_sql);
   $stid_finishing = oci_parse($conn, $finishing_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);

    oci_define_by_name($stid_assembly, 'ASSEMBLY', $assembly);
    oci_execute($stid_assembly);

    oci_define_by_name($stid_welding, 'WELDING', $welding);
    oci_execute($stid_welding);

    oci_define_by_name($stid_drilling, 'DRILLING', $drilling);
    oci_execute($stid_drilling);

    oci_define_by_name($stid_finishing, 'FINISHING', $finishing);
    oci_execute($stid_finishing);

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


    //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 PROGRESS TODAY' class='input'/>";
    }

    if ($assembly == $qty){
        echo "<p><b><font color='#FF8566' size='5'>ASSEMBLY COMPLETED</font></b></p>";
    } else {
        $maxassembly = $qty - $assembly;
        echo "<input id='assembly' name='assembly' type='number' min = '0' max = '$maxassembly' placeholder='ASSEMBLY PROGRESS TODAY' class='input'/>";
    }

    if ($welding == $qty){
        echo "<p><b><font color='#FF8566' size='5'>WELDING COMPLETED</font></b></p>";
    } else {
        $maxwelding = $qty - $welding;
        echo "<input id='welding' name='welding' type='number' min = '0' max = '$maxwelding' placeholder='WELDING PROGRESS TODAY' class='input'/>";
    }

    if ($drilling == $qty){
        echo "<p><b><font color='#FF8566' size='5'>DRILLING COMPLETED</font></b></p>";
    } else {
        $maxdrilling = $qty - $drilling;
        echo "<input id='drilling' name='drilling' type='number' min = '0' max = '$maxdrilling' placeholder='DRILLING PROGRESS TODAY' class='input'/>";
    }

    if ($finishing == $qty){
        echo "<p><b><font color='#FF8566' size='5'>FINISHING COMPLETED</font></b></p>";
    } else {
        $maxfinishing = $qty - $finishing;
        echo "<input id='finishing' name='finishing' type='number' min = '0' max = '$maxfinishing' placeholder='FINISHING PROGRESS TODAY' class='input'/>";
    }

    echo '<section></br></br></br>'; 
    echo '       <input type="submit" value="SUBMIT PROGRESS" class="button red" />';
    echo '       <input type="reset" value="RESET FIELDS" class="button" /></br>';
    echo '       <input type="submit" value="GO TO PAINTING" name="paint" class="button green" /></section>';      




    die;}

    if (isset($_POST['submit'])){
       echo $cutting;
    }
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<title> Update Fabrication Progress</title>

<link type="text/css" rel="stylesheet"   href="../css/goldenform/golden-forms.css"/>
<link type="text/css" rel="stylesheet"   href="../css/goldenform/font-awesome.min.css"/>

   <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 class="bg-wooden">
<div class="gforms">
    <div class="golden-forms wrapper">
        <form>
            <div class="form-title">
                <h2>FABRICATION UPDATE</h2>                   
            </div><!-- end .form-title section -->
            <div class="form-enclose">
                <div class="form-section">
                   <fieldset>
                       <legend>&nbsp Select HEADMARK and the details will be shown <span    class="bubble blue">1</span></legend>
                       <section>
                            <div class="row">
                                <div class="col4 first">
                                    <label for="headmark" class="lbl-text  tleft">HEADMARK :</label>
                                </div><!-- end .col4 section -->
                                <div class="col8 last">

                                    <!-- 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> 
               </div><!-- end .form-section section -->
            </div><!-- end .form-enclose section -->
            <div class="form-buttons">

            </div><!-- end .form-buttons section -->
        </form>
    </div><!-- end .golden-forms section --> 
</div><!-- end .gforms section -->   
<div></div><!-- end section -->
<div></div><!-- end section -->
</body>
</html>

1 个答案:

答案 0 :(得分:1)

欢迎来到SO!

我发现了两个小错误,我认为它会起作用:

  1. post方法添加到表单:<form method="post">
  2. 至少将name属性添加到一个提交按钮:
    • <input type="submit" name="submit" value="SUBMIT PROGRESS" class="button red" />
  3. 此外,建议使用JS来确定单击了哪个提交按钮。例如,您可以添加隐藏元素,并修改其值:

    echo '<input type="submit" value="GO TO PAINTING" ... onclick="$(\'[name=submit_clicked]\').val(\'no\');" />...';
    
    ...
    
    <form method="post">
       <input type="hidden" name="submit_clicked" value="yes" />
       ...
    </form>