Whereas you have the relationship between the tables enterprise and director, in order to store the id
of the company in the director’s register, something like:
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 registration of the company 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 archive cadastro_diretor.php
, where the form is displayed. In the file insere_diretor.php
, you create the director’s record by storing in the field enterprise the id
of the related undertaking.
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 the id
of the company in question. This query returns an entire value and if it is less than 3, redirect the user again to the form page.
See on Ideone and in the Github Gist.
Just didn’t understand the while pq, when you call the
header()
the script ends will not run any more lines below.– rray
In practice he will enter 3 entries, right? because it does not make a form that the person can register
N
directors instead of redirecting.– Daniel Costa
I didn’t understand why I called the header 3 times, but I answered from Loop Repeat.
– Thiago Santos