I have 3 radio buttons, labeled “admin”, “manager” and “employee” in registration.php.
When the new user selects a radio button, it should go to the DB.
When the username and password is given on the login page, it should take the user to the appropriate landing page according to the selected radio button:
- admin goes to admin.php
- manager goes to manager.php
- employee goes to employee.php
What fields should be given for the 2 tables?
This is pretty much the same question as Joining tables in MySql with one common field but different values for the common field which you provided an answer on I see (though I didn’t read it and don’t know if it was correct).
Basically just have ONE table called users with a column for “role” with the values 1-3, 1 being admin, 2 being manager and 3 for employee.
When a user logs in, process the data to check if the password and username are correct which I believe you have already done. If so, check what “role” the user is and redirect them
In response to your comments…
I apologize as I’m not quite sure what you are asking.. But to retrieve the user’s “role” (admin, manager or employee) from the database use
Where $conn is your connection to the database, $username is the username entered into the login form and $password is the password entered into the login form. If either the username or password are incorrect then $role will return as a 0 and you can display an error message.
You should have a default role such as employee because I assume there will be more employees than managers or admins, so go into phpMyAdmin and set the column “role” default to As Defined As 1. This means if a user registers and they do not select a role, it will assign them as employee by default. But you can validate this field and force them to select a role. Anyways…After retrieving the users role you find out what page to direct them to.