Broken MySQL Query [duplicate] - mysql

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
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.

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')

Related

Attempting to insert data into a column

I have a table called design_designs
The table contains 4 columns: id, key, value, nonceId
I'm attempting to run a query to insert into the table:
INSERT INTO design_designs(key, value, nonceId)
VALUES ('test key', 'test value', 'test nonce');
The error i get is:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key, value, nonceId)
VALUES ('test key', 'test value', 'test nonce')' at line 1
Any idea what I'm doing wrong? According to the documentation on queries my query is correct. I'm obviously missing something.
key is a reserved word, you must delimit it:
INSERT INTO design_designs(`key`, value, nonceId) VALUES...

How can I solve this MYSQL INSERT INTO query error?

I have a problem when I try to insert something in my MySQL database.
Here is the error:
Query 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 'LIMIT 1' at line 1 - Invalid query: INSERT INTO banlog (ID, ip, player, admin, reason, day, time) VALUES (NULL, 'Offline','4Gamers','4Gamers','3/3 warns', '3' , '2019-10-13 23:42:09') LIMIT 1
Here is the code:
$query = $this->db->query("INSERT INTO `banlog` (`ID`, `ip`, `player`, `admin`, `reason`, `day`, `time`) VALUES (NULL, 'Offline',?,?,'3/3 warns', '3' , '$time') LIMIT 1", array($info['name'], getUserData($this->session->userdata('logged_in')["id"], "name")));
Thanks.
Try removing LIMIT 1.
I hope this will solve your problem.

SQL request truncated

I've got a little problem with a sql request:
my $sql resquest ( result of echo $sql ):
INSERT INTO match (id, id_match, login, real_login, reponse, date) VALUES (NULL, '11', 'CaptainRida', 'rbikitar', 'oui', '2014-06-07')
and the error
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 'match (id, id_match, login, real_login, reponse, date) VALUES
(NULL, '11', 'Capt' at line 1
the sql request is truncated at 'login'. always 4 characters and BAM truncated.
can anyone help me, I have THE SAME SQL RESQUEST with another table ( exactly the same except rencontre instead of match and id_rencontre instead of id_match)
the "rencontre" request works great and the "match" request is truncated in the error.
MATCH is a MySQL reserved word.
Enclose it in backticks:
insert into `match` (id, id_match, ...
Or, consider changing the name of the table to not use a reserved word (recommended).

Error on MySQL Syntax

I'm trying to teach myself MySQL while working on a project at the same time. I'm using phpMyAdmin.
I'm getting the error: "#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 ''ps_category' ('id_category', 'id_parent', 'id_shop_default', 'level_depth', 'nl' at line 1"
My code:
INSERT INTO 'ps_category'
('id_category', 'id_parent', 'id_shop_default',
'level_depth', 'nleft', 'nright', 'active',
'date_add', 'date_upd', 'position', 'is_root_category')
VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
UPDATE:
I took off the single quotes and still getting the same error:
INSERT INTO ps_category
('id_category', 'id_parent', 'id_shop_default',
'level_depth', 'nleft', 'nright', 'active',
'date_add', 'date_upd', 'position', 'is_root_category')
VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
INSERT INTO `ps_category` (`id_category`, `id_parent`, `id_shop_default`, `level_depth`, `nleft`, `nright`, `active`, `date_add`, `date_upd`, `position`, `is_root_category`) VALUES (6,2,1,0,0,0,1,'2012-04-12 15:12:54','2012-04-12 15:12:54',1,0)
You are using a single quote on the table name. It should be ticks or nothing. It should be noted, the ticks help to ensure properly reading the table name. If you name your table a mysql reserved word, the ticks will prevent it from erroring
The table name should not be entered as a string literal, either remove these '' or put two '' and '' around it like so
INSERT INTO ps_category ...
Or
INSERT INTO `ps_category` ...
Table names should not be quoted

MySQL insert into (enum?) [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
I have a simple mysql database but get an error. It could be the field status, which is an notnull enum('actief', 'wachtend', 'verborgen'), but should be correct this way.
I have checked the comma's 50 times but maybe i'm staring at it too long now. I've tried googling it but still cant find the problem.
All the fields are notnull (i've left out the ones that can be null)
INSERT INTO `restaurants` (id_naam, korte_naam, lange_naam, straat, huisnummer, postcode, plaats, provincie, land, type_aanbieding, type_keuken, lat, long, status) VALUES ('test1', 'test1', 'Test restaurant 1', 'straatnaam', '1', '1234AB', 'plaatsnaam', 'Drenthe', 'landnaam', '2emenu', 'frans', '52', '5', 'verborgen');
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 'long,
status) VALUES ('test1', 'test1',
'Test restaurant 1', 'straatnaam',
'1', ' at line 1
It must be the long field which is causing the error. It's a reserved word in MySQL, so you need to wrap it in backticks:
INSERT INTO `restaurants` (... `long`, status) VALUES ...
Nothing to do with enums though, as you can see.