2016-07-11 55 views
0

以下是我正在使用的代碼, 當我從數據庫中選擇值時,它們被提交到數據庫,但是如果我輸入的數據不在數據庫中,而且我想它提交了,它不會被PHP提交或回顯。 Sombody請幫幫我。JQWidgets Combobox鍵入的值沒有被回顯或提交到數據庫

謝謝。

<?php 
//Jason File 
     #Include the connect.php file 
     include('db_connect2.php'); 
    //get county of selected district 
    $query = "SELECT * FROM primary_schools "; 

     $result = mysql_query($query) or die("SQL Error 1: " . mysql_error()); 
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
      $customers[] = array(
       'Emis_No' => $row['Emis_No'], 
       'District' => $row['District'], 
       'County' => $row['County'], 
       'Subcounty' => $row['Subcounty'], 
       'Parish' => $row['Parish'], 
       'School' => $row['School'] 
       ); 
     } 

     echo json_encode($customers); 
    ?> 

//Script 
<script type=」text/javascript」> 
$(document).ready(function() { 
     //start EMIS code 
      var customersSourcel = 
     { 
      datatype: "json", 
      datafields: [ 
       { name: 'Emis_No'}, 
       { name: 'District'}, 
       { name: 'County'}, 
       { name: 'Subcounty'}, 
       { name: 'Parish'}, 
       { name: 'School'} 
      ], 
      url: 'includes/emis.php', 
      cache: false, 
      async: false 
     }; 

     var customersAdapterl = new $.jqx.dataAdapter(customersSourcel); 

     $("#emis_no").jqxComboBox(
     { 
      source: customersAdapterl, 

      width: 200, 
      height: 25, 
      promptText: "emis", 
      displayMember: 'Emis_No', 
      valueMember: 'Emis_No' 
     }); 

     $("#emis_no").bind('select', function(event) 
     { 
      if (event.args) 
      { 
       var index = $("#emis_no").jqxComboBox('selectedIndex');  
       if (index != -1) 
       { 
        var record = customersAdapterl.records[index]; 
        document.form1.district.value = record.District; 
        $("#county").jqxComboBox({ disabled: false}); 
        document.form1.county.value = record.County; 
        $("#sub_county").jqxComboBox({ disabled: false}); 
        document.form1.sub_county.value = record.Subcounty; 
        $("#parish").jqxComboBox({ disabled: false}); 
        document.form1.parish.value = record.Parish; 
        $("#school").jqxComboBox({ disabled: false}); 
        document.form1.school.value = record.School; 
       } 
      } 
     }); 

回答

0

初始化$customers陣列在PHP文件的開頭$customers = array();你開始推值到它與$customers[] = ...

+0

你好Fredster,我做了你的建議,它不僅帶來了從數據庫中記錄之前;我按照你的建議初始化了; '$ customers = array(); $客戶[] =陣列( 'Emis_No'=> $行[ 'Emis_No'], \t \t '區'=> $行[ '區'], \t \t '縣'=> $行[「縣'], \t \t '縣以下'=> $行[' 縣以下 '], \t \t '教區'=> $行[' 教區 '], \t \t '學校'=> $行[' 學校「] \t);' – WarMichael03