1
Good afternoon, I am a beginner in programming and I have the following difficulty. I have 2 tables :
CREATE TABLE produto(
id_produto int(10) NOT NULL PRIMARY KEY auto_increment,
nome varchar(45) NOT NULL,
)ENGINE=InnoDB;
and the second table:
CREATE TABLE img_produto(
id_img INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
id_produto int(10) NOT NULL,
nome_img VARCHAR(45) NOT NULL,
FOREING KEY (id_produto) REFERENCES produto (id_produto) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB;
My question is how to proceed so that when registering a product with the respective image, the product ID(id_product) of the table produto
is automatically inserted into the table img_produto
in the field id_produto
?
You need to take the (current) id of the inserted product and write to the picture table, more details on: How to rescue ID from last record recorded with Mysqli or that other
– rray