Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

SQLSTATE[42000]:Syntax error or access violation

I am not able to execute an insert statement....when i am trying to run an sql statement i am getting this error.....SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'entry '55555576' for key 'empcorpid')' at line 1

foreach ($err_array as $key => $record) {
    $data[] = [
        'id' => $key,
        'name' => $record[0],
        'username' => $record[1],
        'mdn' => $record[3],
        'employeeCorporateID' => $record[4],
        'department' => $record[5],
        'band' => $record[6],
        'date' => $record[7],
        'errors' => $record[8],
            "INSERT INTO `temporary2` (id,name,username,mdn,employeeCorporateID,department,band,date,errors)  VALUES ($key,$record[0],$record[1],$record[3],$record[4],$record[5],$record[6],$record[7],$record[8]);"

INSERT INTO `temporary2` (id,name,username,[mdn],employeeCorporateID,department,band,[date],[errors])...


you need to escape the string parameters cause you're not bind them.