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

0

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

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

I have a registration form where, at some point, I have fields of two types of addresses to fill: the primary (referring to column localizacao_fk ) and secondary ( correspondencia_fk ). But in the bank, fields of this form such as zip code, street, neighborhood and city are not in the imoveis table, but in enderecos . Therefore, filling in such fields would populate both% w / o% and% w /% (if I want to provide this secondary address).

Help!

Here are the prints of the tables:

Address table:

Realestatetable:

    
asked by anonymous 04.11.2016 / 04:30

1 answer

1

You have to add in the address table first pick up the id and add this id in the buildings.

In your form you have the address and location fields.

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

    
04.11.2016 / 05:14