我不断收到此错误我不断收到一个错误在我的剧本有关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;
尝试'$('#parent选项:选中').val()'并且在运行'$ _POST ['parentVal']查询检查之前' –