Question

MySQL keeps reporting an error when executing the SQL query. Everything looks right to me, but Ive been looking at it for about an hour now.

"INSERT INTO invoices 

(total, generated, account, market, status, name, hash) 

VALUES 

('$total', Now(), '$aid', '$mid', '$name', 'Active', '$hash')"

Error

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 'desc, account, market, status, name, hash) VALUES ('499.99', NOW(), 'System gene' at line 1 (SQL: INSERT INTO invoices (total, generated, desc, account, market, status, name, hash) VALUES ('499.99', NOW(), 'System generated invoice during Market setup/activation.', '6', '9', 'Zac Company - Chandler', 'Active', 'b0521f6668cb87de009866b67b25b458')

I think this is an easy fix that just needs fresh eyes.

Was it helpful?

Solution

There it is

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 'desc, account,

desc is a reserve word and so must be escaped with back quote

`desc`

Also, total is a numeric column; so no need of quoting it

Your sql query should be like below

INSERT INTO invoices (total, generated, `desc`, account, market, status, name, hash) 
                                          <--Here
VALUES (499.99, NOW(), 'System generated invoice during Market setup/activation.',
'6', '9', 'Active', 'Zac Company - Chandler',  'b0521f6668cb87de009866b67b25b458')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top