选择第一个选择框后,根据第一个选择结果显示第二个结果。但是在POST时没有得到任何结果

时间:2015-10-08 09:09:22

标签: javascript php

选择第一个选择框后,根据第一个选择结果显示第二个结果。但是在POST时没有得到任何结果。当我提交表格时,系统提示

  

“注意:未定义的索引:位置在   在线C:\ xampp \ htdocs \ auditsystem \ calendar \ func \ scheduleaction.php   8"

我在显示时得到结果,只在提交表单时显示错误。

func.php

 <?php
  include_once('db.php');
  function getTierOne()
  {
    $result = mysql_query("SELECT DISTINCT * FROM outlet_type")
    or die(mysql_error());

      while($tier = mysql_fetch_array( $result ))

        {
           echo '<option value="'.$tier['id'].'">'.$tier['type'].'</option>';
        }
  }

if(isset($_GET['func'])) {
   drop_1($_GET['drop_var']);
}

function drop_1($drop_var)
{

    $result2 = mysql_query("SELECT DISTINCT * FROM outlet_type_location WHERE outlet_type_id='$drop_var'")
    or die(mysql_error());

    echo '<select name="location" id="tier_one" onChange="showUP(this.value)" class="form-control">
                <option value=" " disabled="disabled" selected="selected">-Select Outlet location-</option>';
           while($drop_2 = mysql_fetch_array( $result2 ))
            {
              echo '<option value="'.$drop_2['location'].'">'.$drop_2['location'].'</option>';
            }
    echo '</select> ';

}
?>

scheduleaction.php(此处显示错误代码)

<?php

    include_once("db.php");

    $auditor_id                 =     $_POST["auditor"];
    $outlet_type_id             =     $_POST["type"];
    $date                       =   $_POST["date"];
    $outlet_location             =     $_POST["location"];


    echo $auditor_id."<br>";
    echo $outlet_type_id."<br>";
    echo $outlet_location;
    echo $date;
?>

表单php

       <script type="text/javascript">
    $(document).ready(function() {
        $('#wait_1').hide();
        $('#drop_1').change(function(){
          $('#wait_1').show();
          $('#result_1').hide();
          $.get("func/func.php", {
            func: "drop_1",drop_var: $('#drop_1').val()
          }, function(response){
            $('#result_1').fadeOut();
            setTimeout("finishAjax('result_1', '"+escape(response)+"')", 0);
          });
            return false;
        });
    });

    function finishAjax(id, response) {
      $('#wait_1').hide();

      $('#'+id).html(unescape(response));
      $('#'+id).fadeIn();
    }
    </script>
  <tr>
                      <label>Oulet Type:</label>
                      <select name="type" id="drop_1" class="form-control">
                      <option value="" selected="selected" disabled="disabled">-Click to select-</option>
                            <?php

                            include ("func/db.php");
                            include ("func/func.php");

                            getTierOne();

                            ?>
                      </select>
                      <span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
                      <span id="result_1" style="display: none;"></span>
                      </tr>

2 个答案:

答案 0 :(得分:1)

试试这个,只有错误是,include()出现在表格之外。

<?php
session_start();
include ("../connection/connect.php");
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Apex Audit System | Administration Panel</title>
    <!-- Core CSS - Include with every page -->
    <link href="../assets/plugins/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="../assets/plugins/pace/pace-theme-big-counter.css" rel="stylesheet" />
    <link href="../assets/css/style.css" rel="stylesheet" />
    <link href="../assets/css/main-style.css" rel="stylesheet" />
    <!-- Page-Level CSS -->
    <link href="../assets/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#wait_1').hide();
        $('#drop_1').change(function(){
          $('#wait_1').show();
          $('#result_1').hide();
          $.get("func/func.php", {
            func: "drop_1",drop_var: $('#drop_1').val()
          }, function(response){
            $('#result_1').fadeOut();
            setTimeout("finishAjax('result_1', '"+escape(response)+"')", 0);
          });
            return false;
        });
    });

    function finishAjax(id, response) {
      $('#wait_1').hide();

      $('#'+id).html(unescape(response));
      $('#'+id).fadeIn();
    }
    </script>
<body>

<?php
include_once("../assets/template/mainlinks2.php");
include_once("../assets/template/sidebar3.php");
?>        <!--  page-wrapper -->
        <div id="page-wrapper">


            <div class="row">
                 <!--  page header -->
                <div class="col-lg-12">
                    <h1 class="page-header">Setup New Schedule</h1>
                </div>
                 <!-- end  page header -->
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Assign New Schedule
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">

                             <form action="func/scheduleaction.php" role="form" method="POST" name="form">
            <table>
                  <div class="form-group">

                        <?php

                            include ("func/db.php");
                            include ("func/func.php");
                        ?>
                      <tr>
                      <label>Auditor Name:</label>
                      <select class="form-control" name="auditor">
                                <?php
                                $result =  $db->query("SELECT * FROM auditor");
                                while($row = mysqli_fetch_array($result))
                                {
                                    echo '<option value="'.$row["id"].'">'.$row["auditor_name"].'</option>';
                                    }
                                echo "</select>";
                                ?>
                  </tr>


                      <tr>
                      <label>Oulet Type:</label>
                      <select name="type" id="drop_1" class="form-control">
                      <option value="" selected="selected" disabled="disabled">-Click to select-</option>
                            <?php

                            getTierOne();

                            ?>
                      </select>
                      <span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
                      <span id="result_1" style="display: none;"></span>
                      </tr>

                      <tr>
                      <label>Audit Date:</label>
                      <input type="date" name="date" class="form-control" required="required">
                      </tr>
                   <br>
                   <tr>
                   <td><button type="submit" class="btn btn-primary">Submit Button</button></td>
                   <td><button type="reset" class="btn btn-success">Reset Button</button></td>
                   </tr>

                                        </div>
                             </form>
                             </table>
                            </div>

                        </div>
                    </div>
                    <!--End Advanced Tables -->

                </div>
            </div>
        </div>
        <!-- end page-wrapper -->

    </div>
    <!-- end wrapper -->


    <!-- Core Scripts - Include with every page -->
    <script src="../assets/plugins/jquery-1.10.2.js"></script>
    <script src="../assets/plugins/bootstrap/bootstrap.min.js"></script>
    <script src="../assets/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="../assets/plugins/pace/pace.js"></script>
    <script src="../assets/scripts/siminta.js"></script>

</body>

</html>

答案 1 :(得分:0)

<?php
session_start();
include ("../connection/connect.php");
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Apex Audit System | Administration Panel</title>
    <!-- Core CSS - Include with every page -->
    <link href="../assets/plugins/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <link href="../assets/plugins/pace/pace-theme-big-counter.css" rel="stylesheet" />
    <link href="../assets/css/style.css" rel="stylesheet" />
    <link href="../assets/css/main-style.css" rel="stylesheet" />
    <!-- Page-Level CSS -->
    <link href="../assets/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#wait_1').hide();
        $('#drop_1').change(function(){
          $('#wait_1').show();
          $('#result_1').hide();
          $.get("func/func.php", {
            func: "drop_1",drop_var: $('#drop_1').val()
          }, function(response){
            $('#result_1').fadeOut();
            setTimeout("finishAjax('result_1', '"+escape(response)+"')", 0);
          });
            return false;
        });
    });

    function finishAjax(id, response) {
      $('#wait_1').hide();

      $('#'+id).html(unescape(response));
      $('#'+id).fadeIn();
    }
    </script>
<body>
  <?php

  include ("func/db.php");
  include ("func/func.php");
   ?>
<?php
include_once("../assets/template/mainlinks2.php");
include_once("../assets/template/sidebar3.php");
?>        <!--  page-wrapper -->
        <div id="page-wrapper">


            <div class="row">
                 <!--  page header -->
                <div class="col-lg-12">
                    <h1 class="page-header">Setup New Schedule</h1>
                </div>
                 <!-- end  page header -->
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Assign New Schedule
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                             <form action="func/scheduleaction.php" role="form" method="POST" name="form">
                             <table>

                  <div class="form-group">
                      <tr>
                      <label>Auditor Name:</label>
                      <select class="form-control" name="auditor">
                                <?php
                                $result =  $db->query("SELECT * FROM auditor");
                                while($row = mysqli_fetch_array($result))
                                {
                                    echo '<option value="'.$row["id"].'">'.$row["auditor_name"].'</option>';
                                    }
                                echo "</select>";
                                ?>
                  </tr>


                      <tr>
                      <label>Oulet Type:</label>
                      <select name="type" id="drop_1" class="form-control">
                      <option value="" selected="selected" disabled="disabled">-Click to select-</option>
                            <?php

                            getTierOne();

                            ?>
                      </select>
                      <span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
                      <span id="result_1" style="display: none;"></span>
                      </tr>

                      <tr>
                      <label>Audit Date:</label>
                      <input type="date" name="date" class="form-control" required="required">
                      </tr>
                   <br>
                   <tr>
                   <td><button type="submit" class="btn btn-primary">Submit Button</button></td>
                   <td><button type="reset" class="btn btn-success">Reset Button</button></td>
                   </tr>

                                        </div>
                             </form>
                             </table>
                            </div>

                        </div>
                    </div>
                    <!--End Advanced Tables -->

                </div>
            </div>
        </div>
        <!-- end page-wrapper -->

    </div>
    <!-- end wrapper -->


    <!-- Core Scripts - Include with every page -->
    <script src="../assets/plugins/jquery-1.10.2.js"></script>
    <script src="../assets/plugins/bootstrap/bootstrap.min.js"></script>
    <script src="../assets/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="../assets/plugins/pace/pace.js"></script>
    <script src="../assets/scripts/siminta.js"></script>

</body>

</html>