I’m normalizing my database, to I’m trying to set the value of a field the same as the ID for that row so I can join tables.
I tried using LAST_INSERT_ID(), but it doesn’t work. I don’t get a error, but I only get zeros.
INSERT INTO `eleves` (`user_id`,
`first_name`, `last_name`,
`username`, `groupe`,
`password`, `courriel`,
`active`, `auteur`,
`citations`, `absurde`,
`vocabulaire`, `analyse`,
`themes`, `personnages`)
VALUES (NULL,
'Jane', 'Doe',
'janedoe', '400',
'password', 'jane@doe.com',
'1', LAST_INSERT_ID(),
LAST_INSERT_ID(), LAST_INSERT_ID(),
LAST_INSERT_ID(), LAST_INSERT_ID(),
LAST_INSERT_ID(), LAST_INSERT_ID());
Thanks!
It seems, during your MySQL session there happened no auto generated id was inserted. And hence for the fields for which you want to fill
last_insert_id()must be azerobut not anempty(NULL?, SPACE?).Try to define a primary key with auto increment in your table and let your generate a new record. And see what happens !
See the following example: