Send more than one record to the same register in the Database

Asked

Viewed 21 times

1

I have dependency registration with the form sending correctly to the BD. I have come across the problem that I have not noticed that the worker may have more than one dependent, I would like to know how I can add more than one dependent to the employee, create more fields for if you have other dependents but how will you stay and/ or send to my BD and record with the employee?

This is my dependent add code;

<tr>
<td>Tipo de Dependente:</td>
  <td><select name="tpDep" id="tpDep">
    <option></option>
    <option value="01">Cônjuge;</option>
    <option value="02">Companheiro(a) com o(a) qual tenha filho ou viva há mais de 5 (cinco) anos ou possua Declaração de União Estável;</option>
    <option value="03">Filho(a) ou enteado(a);</option>
    <option value="04">Filho(a) ou enteado(a), universitário(a) ou cursando escola técnica de 2º grau;</option>
    <option value="06">Irmão(ã), neto(a) ou bisneto(a) sem arrimo dos pais, do(a) qual detenha a guarda judicial;</option>
    <option value="07">Irmão(ã), neto(a) ou bisneto(a) sem arrimo dos pais, universitário(a) ou cursando escola técnica de 2° grau, do(a) qual detenha a guarda judicial;</option>
    <option value="09">Pais, avós e bisavós;</option>
    <option value="10">Menor pobre do qual detenha a guarda judicial;</option>
    <option value="11">A pessoa absolutamente incapaz, da qual seja tutor ou curador;</option>
    <option value="12">Ex-cônjuge;</option>
    <option value="99">Agregado/Outros;</option>
</tr>

<tr>
  <td width="69">Nome:</td>
  <td width="546"><input name="nmDep" type="text" id="nmDep" size="70" maxlength="70" />
    <span class="style1"></span></td>
</tr>

<tr>
  <td>Data de Nascimento:</td>
  <td><input name="dtNascto" type="text" placeholder="DD/MM/AAAA" id="dtNascto" size="10" maxlength="10" />
         <small><small><i><span class="style1"></span></td></small></small></i>
</tr>

<tr>
  <td width="69">CPF:</td>
  <td width="546"><input name="cpfDep" type="text" id="cpfDep" size="15" maxlength="11" />
    <span class="style1"></span></td>
</tr>

<tr>
  <td>Deduz IRRF?</td>
  <td><input name="depIRRF" type="radio" value="S" />
    Sim
    <input name="depIRRF" type="radio" value="N" />
    Não <span class="style1"></span> </td>
<tr>    
<td>Salário Família?</td>
  <td><input name="depSF" type="radio" value="S" />
    Sim
    <input name="depSF" type="radio" value="N" />
    Não <span class="style1"></span> </td>  
</tr>   
<tr>    
<td>Defic. Fisica ou Mental?</td>
  <td><input name="incTrab" type="radio" value="S" />
    Sim
    <input name="incTrab" type="radio" value="N" />
    Não <span class="style1"></span> </td>  
</tr>

1 answer

2

The ideal is to have a table for the worker and a separate table only for dependents. Then you use the id worker as foreign key in the dependent table.

Already on the schedule. You allow the addition of a number of dependents in a fixed (3 for example) or dynamic way, with a "Add Dependent" button that through javascript adds fields in the worker’s own registration form. Or a specific separate route only for the registration of dependents after worker registration.

Anyway, you will have to make 2 querys of INSERT, one for the worker and another for each dependent having as foreign key of worker, the worker previously registered.

  • Thank you David, I stopped here and thought the same thing, doing it separately, will be the best way even. Thank you very much!

Browser other questions tagged

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