Error while inserting multiple inputs in sql
P粉118698740
P粉118698740 2023-09-14 21:56:33
0
1
420

This is the query I use const dbQuery = INSERT INTO tasks (activity, type, participants, price, link, key, accessibility) VALUES ('${activity}','${type}','${participants}' ,'${price}','${link}','${key}','${accessibility}');

This is the error I receive: "There is an error in your SQL syntax; check the manual for your MySQL server version for use near 'key,accessibility) VALUES ('Repaint a room in your house','recreational','1' Correct syntax) ,'0.' on line 1"

The received key value is similar to "4877086"

I thought it was a data type issue in sql so tried using bigint, varchar and int but still got the same error. Also tried converting the key to a number. If I remove the key from the grammar I receive the result perfectly. (Using Tableplus for MySql)

P粉118698740
P粉118698740

reply all(1)
P粉659378577
  • The word "key" is a reserved keyword in MySQL.

  • Avoid using it as a column name.

  • If you must use it, you can enclose it in backticks (`) to indicate that it is a column name and not a keyword.

    const dbQuery = `INSERT INTO tasks (activity, type, participants, price, link, \`key\`, accessibility) 
     VALUES ('${activity}', '${type}', '${participants}', '${price}', '${link}', '${key}', '${accessibility}')`;
  • Check if this is the cause of your problem.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!