2014-03-02 45 views
0

我不斷收到此錯誤我不斷收到一個錯誤在我的劇本有關verable

致命錯誤:未捕獲的異常「PDOException」有消息「SQLSTATE [42000]:語法錯誤或訪問衝突:1064您有一個錯誤在你的SQL語法中;檢查對應於您的MySQL服務器版本的手冊,以便在第6行的C:\ wamp \ www \ notaryaccounting \ contact.php中的''第1行'附近使用正確的語法。

我找不出方法。在contact.php中,如果我將$ _POST ['parentVal']替換爲腳本運行的數字1。所以它與從jquery腳本傳遞parentVal變量有關。

當我使用$ _GET ['parentVal']進行設置並使用開發人員工具時,我可以看到該變量存在於是腳本應該可以工作,但不會。

<html> 
<head> 
    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script> 

    <script type="text/javascript"> 
      $(function(){      
       $('#parent').change(function(){ //on change event 
       var parentVal = $('#parent').val(); //<----- get the value from the parent select 
       $.ajax({ 
        url  : 'contact.php', //the url you are sending datas to which will again send the result 
        type : 'POST', //type of request, GET or POST 
        data : { parentValue: parentVal}, //Data you are sending 
        success : function(data){$('#child').html(data)}, // On success, it will populate the 2nd select 
        error : function(){alert('an error has occured')} //error message 
       }) 
      }) 

      }) 
    </script> 
</head> 
<body> 

    Customer: 
    <select name="customer" id="parent"> 
     <option>-Select a Customer-</option> 
    <?php 

    include("connect.php"); 
    $pid = $_SESSION['profile']['id']; 
    foreach($db->query("SELECT * FROM customers WHERE pid = '$pid'") as $row) { 
     echo "<option value=" . $row['id'] . ">" . $row['name'] . "</option>"; 
} 
     ?> 
    </select> 


Contact: 
<select name="contact"id="child"/> 
<option>-Select a Contact-</option> 
</select> 



    </body> 
</html> 





<?php 
include("connect.php"); 

$custid = $_POST['parentVal']; 

foreach($db->query('SELECT * FROM contact WHERE custid =' . $custid) as $row) { 
    $results.=("<option value=" . $row['id'] . ">" . $row['name'] . "</option>"); 
} 
echo $results; 
+0

嘗試'$('#parent選項:選中').val()'並且在運行'$ _POST ['parentVal']查詢檢查之前' –

回答

1

您與parentValue名發送您的數據和服務器使用parentVal。更改名稱。

$_POST['parentValue']; 

$_POST['parentVal'] 

此外,你有SQL語法錯誤:

變化

$db->query('SELECT * FROM contact WHERE custid =' . $custid 

要:

$db->query("SELECT * FROM contact WHERE custid='$custid'") 
+0

謝謝你看看,但沒有看到我的錯誤 –

相關問題