Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahzadyounas's avatar

Teacher and student table registered with same email. how fix it

I have three tables "Admin", "Teachers" and "Students", in each table i choose Field "Email" for login on single login panel, i have 2 problems

  1. An email that is already register in second table can be register in other table but i want to be unique email for these three table. which logic i use??
  2. Which method i use that i want to login these three panels using single login form.
0 likes
3 replies
himanshu-dhiman's avatar

Hi @shahzadyounas ,

This problem seems to me like an architectural problem more than a code logic problem.

I will be just suggesting you a different way which you can implement in the application.

Currently, you have three different kinds of Users: Admin, Teachers, and Students in three different tables. But, I will suggest you have a single table 'Users'. In that users table, you can have an attribute as 'type' which defines a User type which could be: Admin, Student or Teacher. And Make the 'Email' as Unique. It will solve your mentioned both problems in an easy way. While logging in, just check the credentials in 'Users' table, if credentials are verified then check the User->type using 'if statement' and return the relevant view according to the User type.

Why I am focusing on architecture because if you will go with your architecture, it will be too much pressure on the application while querying three kinds of tables just to log in a User. With the new approach, it is easy to implement, and not too much hectic for the development and the application performance.

Just think about the application performance also while development.

Thanks.

Snapey's avatar

what if a teacher also needs to do admin? or if admin is also a student?

Everyone should be a user from the point of view of logging in. Roles should then determine what they are allowed to do

Inquisitive's avatar

Use a single table for all users, and store all the information related to a person. Then, provide them different roles such as teacher,student and Admin. Based, on if one person can have multiple roles or not, you can design database structure.

Please or to participate in this conversation.