0

I'm attempting to query my database, but am getting the error:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual th
at corresponds to your MySQL server version for the right syntax to use near 'gr
oup = 'new_fire', date = '2014-03-16', price = '', customer = '', seller = 'no'
at line 1

But I can't seem to find the syntax error. I assume it has to do with the way that I'm putting the query together with the nodeMySQL module.

Here's my relevant node query snippet:

var salesData = [category, group, date, price, customer, name, commission];

...

connection.query(
'INSERT INTO `officeball`.`sales_entries` SET category = ?, group = ?, date = ?, price = ?, customer = ?, seller = ?, commission = ?',
salesData
)

And finally the query generated by phpmyadmin that I mean to execute:

INSERT INTO `officeball`.`sales_entries` (`sale_id`, `category`, `group`, `date`, `price`, `customer`, `seller`, `accepted`, `commission`, `commission_status`) VALUES ('', 'fire', 'new_fire', '2014-03-16', '123', 'joey bob', 'node user', '', '34', '')

I left the accepted and commission_status out in the node query, they can remain blank.

Is my error in this query?

1 Answer 1

4

group is mysql reserved keyword, surround it by backticks like this:

   INSERT INTO `officeball`.`sales_entries` SET category = ?, `group` = ? .....

Here are the reserved keywords from documentation.

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

1 Comment

Ahh. I would've never discovered that. You've saved my much time dear sir. Thanks!

Your Answer

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