How to pass company id to employee table?

Asked

Viewed 190 times

3

I have a company table and another employee.

Company table:

id_emp | tipo | documento | fantasia | email | celular | senha | data_cadastro | ativo

Example:

 1 | pessoa juridica | 05.142.333/0001-21 | petstop caes e gatos | [email protected] | (21) 8651-0801 | MD5 | 22/11/2015 | 09:49:00 | 1

Employee table:

id_func | sexo | nome | sobrenome | funcao | celular | email | senha | ativo | data_cadastro | id_emp  

Example:

1 | M | Paulo | Santos | veterinario | (21)8651-0001 | [email protected] | MD5 | 1 | 22/11/2015 | 09:49:00 | 1 | ???

Before my question, I will inform the procedure I do to get here: On my website, the company (petstop caes and cats) makes her registration. After registration, the system sends a link to the registered email ([email protected]) with the MD5 password. And, it goes a link to the activation of it. When it makes the activation, just below it makes the login.

I did using this example here.

It was created an employee registration form, that is, after logging in, it will register the employee, and after saving, in the employee table, associate this to the company.

  • 2

    Welcome to Sopt. But, what’s your question?

  • 2

    Taking advantage that you have already read the [tour], read also the [Ask]. :)

  • I’m wanting to take the company id and play in the id_emp field of employee registration.

  • at the time of registration of the company you also register an employee?

  • 1

    Right, but what are you using? In PHP, PDO? In the database, Mysql, etc. Without so many details it is difficult to answer.

  • I’m using Mysql + PHP

Show 1 more comment

2 answers

2

You can put a field in the form with type="hidden" and with the ID of the company being the value of that field.

When submitting the form, you capture the value of that field and save it in the column id_emp on the table funcionário. For example:

<input type="hidden" name="id_emp" value="1">
  • to get the value of this field use: $id_emp = POST['id_emp']. Then just put in the INSERT that saves in the database.

  • I don’t have to get the url of the company that accessed through the activation link?

0

This would actually be a primary key relationship id_emp on the table empresa and foreign key id_emp on the table funcionario. IN phpmyadmin itself you can create the indexes and then create the relationship between these two tables.

Follow link to reference: video

  • Ok Igor! Maybe I misinterpreted my question in the forum. On my website, you can register several companies and each company with its employees. Then, after the company administrator makes the registration, the link goes to him. In this link is going the ID of the company, however, in the employee registration form, does not appear the id of the company to link this employee. Got it?

Browser other questions tagged

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