Considering that you have the relationship between the company and director tables in order to store the id
of the company in the director's directory, something like: p>
create table empresas
(
id int,
name varchar(255)
);
create table diretores (
id int,
name varchar(255),
empresa int
);
In a file, possibly called insert_empresa.php
, the company register is made. For example:
insert into empresas (id, name) values (1, "empresa_1");
This insert
generates a id
, related to the company record, which is passed to the cadastro_diretor.php
file, where the form is displayed. In the insere_diretor.php
file, you create the director record by storing the id
of the related company in the company field.
insert into diretores (id, name, empresa) values (1, "diretor_1", 1);
To know if the three directors have not yet been registered, just count the number of records in the bank:
select count(*) from diretores where empresa = 1;
Where empresa = 1
refers to id
of the company in question. This query returns an integer value and if it is less than 3, redirect the user back to the form page.
See the Ideone and Github Gist .