0
Hi, I’m having a little trouble checking if a dependent’s name has already been registered. I have a form where the person can add up to 5 names of dependents and after that is generated a tab with the names.
Form field, have a button to add more fields.
<input type="text" name="nome_dep[]" id="nome_dep" placeholder="Nome do Dependente" class="form-control>
Page of the Controller
$nome = $this->input->post('nome_dep');
$nbanco = "SELECT `nome_dependente` FROM `beneficios_dependentes` WHERE `nome_dependente` IN ? ";
$nome_existe = $this->db->query($nbanco,array($nome))->result_array();
if (empty($nome_existe))
{
echo "Não tem nome no banco";
}
else
{
echo "Tem nome no banco";
}
My difficulty is in checking if the name of the dependent has already been registered, for example: he registered John - OK, but the other day he registered John and Mary is falling that already has the name registered in the bank. I need to do an Insert if it has not been registered and an update if it is already registered
But There are namesakes, the correct would not be to add the
nome_dependente
and thecpf_dependente
, so that you can compare the CPF’s and not the names? The end there are many "Luiz Inácio Lula", but not all steal countries. some just want to program.– Vinicius De Jesus
kkkk, I will change the name of the kkkk profile, so dependents are linked with an associate, will I get something in that direction?
– Luiz Inácio Lula
I think it would be less "correct", suppose an associate has twin children with the same name... he could not put the two children because they have the same names? Why the
SELECT nome_dependente FROM beneficios_dependentes WHERE nome_dependente = $nome AND associado_id = $id_do_associado
wouldn’t do? How are your tables?– Vinicius De Jesus
Table dependent benefits has: id_dependent benefits, dependent name_name, dependent associate_dependents (FK), the problem is that the name comes in an array name="name_dep[]", I need to separate each one and check in the table. The issue of twins I believe will not have problem, but you gave an idea to add the ID
– Luiz Inácio Lula
I never used codeignite, but if the problem is how to do the
select
for all the names of aarray
, you use some repeat loop like theforeach()
. I will publish the answer as I believe it would be.– Vinicius De Jesus