Reputation: 9
here is the Error Database query failedYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 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
$('.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
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; check the manual that corresponds to your MySQL server version for the right syntax to use near ' )' at line 4
Upvotes: 0
Views: 81
Reputation: 4577
You cannot use INSERT statement with WHERE clause in a simple query. An INSERT will create a new row with his own field 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.
Upvotes: 2
Reputation: 1945
try with VALUES instead of VALUE $queryAdd = "INSERT INTO packagebylessontype (packageid)VALUES({$value}) WHERE lessontypeid = {$idToBeAdded}";
Upvotes: 0
Reputation: 345
Well give a space between (packageid) and VALUES, I think this might work and ofcourse it should be VALUES not VALUE
Upvotes: 0
Reputation: 442
You have a syntax error - instead of VALUE type VALUES.
Also you are not properly escaping your sql params thus leading yourself open to sql injections.
Upvotes: 2