[英]Database query failedYou have an error in your SQL syntax;
here is the Error Database query failedYou have an error in your SQL syntax; 这是错误数据库查询失败您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 4..
请查看与您的MySQL服务器版本相对应的手册,以找到在第4行“”附近使用的正确语法。
im so tired to fixed this error and i dont know what should i do.. 我很累解决这个错误,我不知道该怎么办。
<form id="packageLessonType" method="post">
<table id="listpackage" class="table table-condensed table-hover">
<thead>
<tbody id="responsePackage">
<tr id="pack_1">
<td>1 Month Unlimited</td>
<td id="td-" class="center">
<input type="checkbox" value="1" name="package[]">
</td>
</tr>
<tr id="pack_2">
<td>6 Lessons</td>
<td id="td-" class="center">
<input type="checkbox" value="2" name="package[]">
</td>
</tr>
<tr id="pack_3">
<td>6 Months Unlimited</td>
<td id="td-" class="center">
<input type="checkbox" value="3" name="package[]">
</td>
</tr>
<tr id="pack_4">
<td>12 Months Unlimited</td>
<td id="td-" class="center">
<input type="checkbox" value="4" name="package[]">
</td>
</tr>
<tr id="pack_5">
<td>Group of 4</td>
<td id="td-" class="center">
<input type="checkbox" value="5" name="package[]">
</td>
</tr>
<tr id="pack_6">
<td>Group of 8 </td>
<td id="td-" class="center">
<input type="checkbox" value="6" name="package[]">
</td>
</tr>
</tbody>
</table>
</form>
Ajax Script Ajax脚本
$('.packAddLt_btn').click(function(e){
var clickedIdadded = this.id.split('_');
var addedId = clickedIdadded[1];
var addedPackageLesson = "&lessonPackageAdded="+addedId;
var addLesPackCheck = $('#packageLessonType').serialize();
var submitData = addLesPackCheck+addedPackageLesson;
//alert(submitData);
$.ajax({
type:"POST",
url:"<?php echo get_stylesheet_directory_uri(); ?>/includes/response_lessons_packages.php",
dataType:"text",
data:submitData,
success: function(response){
alert(response);
},
error: function(xhr, ajaxOtions, thrownError){
alert(thrownError);
}
});
});
PHP CODE PHP代码
if($_POST['package']){
$checkBox= $_POST['package'];
$idToBeAdded = $_POST['lessonPackageAdded'];
foreach($checkBox as $value){
$queryAdd = "INSERT INTO packagebylessontype (packageid)VALUE({$value}) WHERE lessontypeid = {$idToBeAdded}";
$addedLessonByPackage = mysql_query($queryAdd, $connection);
}
confirm_query($addedLessonByPackage);
if($addedLessonByPackage){
echo "You've successfuly deleted your Package..";
mysql_close($connection);
}else{
header('HTTP/1.1 500 Looks like mysql error, could not insert record!');
exit();
}
}
Error: 错误:
Database query failedYou have an error in your SQL syntax; 数据库查询失败您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 4
检查与您的MySQL服务器版本相对应的手册以在第4行的')'附近使用正确的语法
You have a syntax error - instead of VALUE type VALUES. 您有语法错误-而不是VALUE类型VALUES。
Also you are not properly escaping your sql params thus leading yourself open to sql injections. 另外,您没有正确地转义sql参数,从而导致自己无法使用sql注入。
You cannot use INSERT statement with WHERE clause in a simple query. 您不能在简单查询中将INSERT语句与WHERE子句一起使用。 An INSERT will create a new row with his own field lessontypeid.
INSERT将使用他自己的字段lessontypeid创建一个新行。 Maybe you are trying to perform an update.
也许您正在尝试执行更新。
If you want to make an insert, the correct way would be: 如果要插入,正确的方法是:
INSERT INTO packagebylessontype (packageid) VALUES ('A')
If you want to perform an update, then: 如果要执行更新,则:
UPDATE packagebylessontype SET packageid = 'A' WHERE lessontypeid ='1'
Please note that I'm using WHERE clause only in UPDATE operation, as a reference to locate register to be updated. 请注意,我仅在UPDATE操作中使用WHERE子句,作为查找要更新的寄存器的参考。
好在(packageid)和VALUES之间留一个空格,我认为这可能有效,当然应该是VALUES而不是VALUE
尝试使用VALUES而不是VALUE $ queryAdd =“插入到packagebylessontype(packageid) VALUES ({$ value})WHERE lessontypeid = {$ idToBeAdded}”中;“
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.