سؤال

Hi I have the following with the below code? I have another statement which works but it is to another table and without the project_id column.

(
    [0] => 42000
    [1] => 1064
    [2] => 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 'change (title, description, project_id) VALUES ('Test1', 'Test1', '1')' at line 1
)

$sql = "INSERT INTO change (title, description, project_id) VALUES (:title, :description, :project_id)";
$query = $db->prepare($sql);
$query->execute(array(":title" => $title,
        ":description" => $description,
        ":project_id" => $row_id));

$arr = $query->errorInfo();
print_r($arr);

Where have I gone wrong?

هل كانت مفيدة؟

المحلول 2

When you make tables always check here for reserved keywords in mysql

Your table name is a reserved keyword which is why you have these errors.

Use backticks to fix the problem. But i will recommend that you change the table name.

Sometimes prople find it hard to locate the backticks, it's above your tab key if you are using a normal qwerty or azerty keyboard.

نصائح أخرى

Always encapsulate your table and field names in backticks:

INSERT INTO `change` (`title`, `description`, `project_id`) VALUES (:title, :description, :project_id)

In this case: CHANGE is a keyword in MySQL, so your statement doesn't interpret it as a table name.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top