0

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'
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
Chawki Tazzi
  • 225
  • 3
  • 10
  • 2
    Possible duplicate of ["Unknown column in 'field list'", but column does exist](https://stackoverflow.com/questions/15989529/unknown-column-in-field-list-but-column-does-exist) – Droow Nov 26 '17 at 14:19
  • you declared `ID_CAT` as a primary key and set `AUTO_INCREMENT` for it. You don't have to `INSERT` it. (It won't solve anything but it may avoid many collision problems in the future) – Hollyol Nov 26 '17 at 14:20

2 Answers2

2
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.

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
0

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360