Chawki Tazzi
Chawki Tazzi

Reputation: 245

Unknown column 'XXXXX' in 'field list'

i'm trying to create a table in mysql

CREATE TABLE IF NOT EXISTS`catalogue`(
`ID_CAT` int(11) NOT NULL AUTO_INCREMENT,
`NOM_CAT` varchar(25) NOT NULL,
`DESCRIOTION` text NOT NULL,
`PHOTO` varchar(25) NOT NULL,
PRIMARY KEY (`ID_CAT`)
)ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

INSERT INTO catalogue (ID_CAT,NOM_CAT,DESCRIOTION,PHOTO) VALUES
(1,`Ordinateures`,`Ordinateures`,`ordinateures.jpg`),
(2,`Imprimantes`,`Imprimantes`,`imprimantes.jpg`),
(3,`Televiseur`,`Televiseur`,`televiseur;jpg`),
(4,`Accessoirs`,`Accessoirs`,`accessoirs.jpg`);

but I keep getting the same message:

#1054 - Unknown column 'Ordinateures' in 'field list'

Upvotes: 0

Views: 477

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521093

I'm not sure if the mistake you made qualifies as a simple typo or something more than that. In any case, you are incorrectly placing backpacks around the string literals in your INSERT statement. Use single quotes instead:

INSERT INTO catalogue (ID_CAT, NOM_CAT, DESCRIOTION, PHOTO)
VALUES
    (1, 'Ordinateures', 'Ordinateures', 'ordinateures.jpg'),
    (2, 'Imprimantes', 'Imprimantes', 'imprimantes.jpg'),
    (3, 'Televiseur', 'Televiseur', 'televiseur;jpg'),
    (4, 'Accessoirs', 'Accessoirs', 'accessoirs.jpg');

Backticks are meant for escaping column, table, and database names. Hence, you could have written the above INSERT as:

INSERT INTO `catalogue` (`ID_CAT`, `NOM_CAT`, `DESCRIOTION`, `PHOTO`)
VALUES
...

Here I have escaped the table and column names in backpacks. One reason you might want to escape names is if they contain something which is a reserved MySQL keyword.

Upvotes: 0

Tommaso Belluzzo
Tommaso Belluzzo

Reputation: 23675

INSERT INTO catalogue (NOM_CAT,DESCRIOTION,PHOTO) VALUES
    ('Ordinateures','Ordinateures','ordinateures.jpg'),
    ('Imprimantes','Imprimantes','imprimantes.jpg'),
    ('Televiseur','Televiseur','televiseur;jpg'),
    ('Accessoirs','Accessoirs','accessoirs.jpg');

You were using backquotes instead of single quotes ' for your insertion values. Also (but this is just a small improvement) there is no need to manually insert AUTO_INCREMENT values.

Upvotes: 2

Related Questions