How to insert data into another table from the foreign key?

Asked

Viewed 475 times

0

I have a table in my database called imoveis where I have some columns, standing out localizacao_fk and correspondencia_fk, both foreign keys that reference the table enderecos. What I want to know is how to insert data into the table imoveis so that the stand of the columns localizacao_fk and correspondencia_fk automatically be done in the table enderecos.

An overview of what I intend to do is as follows:

I have a registration form where, at a certain point, I have fields of two types of addresses to be filled: the primary (referring to the column localizacao_fk) and high school (correspondencia_fk). But in the bank, fields of this form as zip code, street, neighborhood and city are not in the table imoveis, and yes in enderecos. Therefore, the filling of such fields would populate both localizacao_fk how much correspondencia_fk (if I wish to provide this secondary address).

Help!

Here are the prints of the tables:

Address table: tabela endereços

Real estate table: tabela imóveis

  • Could post your tables.

  • I already made the links available in the post.

1 answer

1

vc have to add first in address table pick up id and add this id in immobles.

in your form have the address fields location and match.

when you save the form, first save the address table. as it may be 2 addresses save the first save the id in a variable then the same with the second. finalize putting the ids in immovable

  • Location and correspondence are foreign keys of the address table.

  • I made available in the post the print links of the tables.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.