0

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

2
  • side note: id cannot be duplicated. Commented Jan 22, 2015 at 6:44
  • 1
    its values, and having a where clause on insertion doesn't make sense Commented Jan 22, 2015 at 6:46

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah sorry :) I was posting from my mobile so i could not see the rest of the query with WHERE. That's true - you can't use conditions with INSERT. What you want is to also insert the lessontypeid (incase you really want to insert) OR use an UPDATE query - like "manuelbcd" said above.
In case you wanted to do an insert - here it is: INSERT INTO packagebylessontype (packageid, lessontypeid) VALUES ({$value}, {$idToByAdded});
2

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.

Comments

0

Well give a space between (packageid) and VALUES, I think this might work and ofcourse it should be VALUES not VALUE

Comments

0

try with VALUES instead of VALUE $queryAdd = "INSERT INTO packagebylessontype (packageid)VALUES({$value}) WHERE lessontypeid = {$idToBeAdded}";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.