我不断收到此错误
fatal error :未捕获异常“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;
最佳答案
您正在使用 parentValue
名称发送数据,并在服务器中使用 parentVal
。更改名称。
$_POST['parentValue'];
不是
$_POST['parentVal']
此外,您还有 SQL 语法错误:
改变
$db->query('SELECT * FROM contact WHERE custid =' . $custid
致:
$db->query("SELECT * FROM contact WHERE custid='$custid'")
关于php - 我的脚本中不断出现有关 verable 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22133682/