Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want a small help...
am new to php coding...
i have been desiging a project for my college..
i made a login and registration app... bt i am unable to mix the user and admin code..
can i hav any help..
user table consists of username,email,password
and admin the same things...
and thanks in advance..
the below code is for login of user..
for login of admin i created a new table and inserted he data..
how to create both of the using a same table a one php file..
please help....

What I have tried:

$email = $_POST["email"];
$pass = $_POST["password"];
require "inti.php";

$query = "select * from userinfo where email like '".$email."' and password like '".$pass."';";
$result = mysqli_query($con,$query);

$response = array();
$code = "login_true";
$row = mysqli_fetch_array($result);
$name = $row[0];
$message = "login sucess...".$name;
echo json_encode(array("server_response"=>$response));


$response = array();
$code = "login_false";
$message = "login failed.....try again..";
echo json_encode(array("server_response"=>$response));
Updated 3-May-16 4:50am
Sergey Alexandrovich Kryukov 3-May-16 10:52am    
If you are going to differentiate some, you have use authentication — I can see some log-on code. If you have that, probably you have some persistent data layer where you user information is stored, some kind of database. Your code shows that you really use MySQL. And if you have that database, it's up to you what user data you put in user records and how you classify the users. So, what's the problem?
Dheeraj Cidda 3-May-16 12:15pm    
actually sir,i am creating a project for my college. i have created a data base and tables for both user and admin and accessing them by using different login pages,like for user login i used one page and for admin login i used another.the code i posted is just simply for login for user in his login page and admin in his login i want to access both of them from a common login page.both user and admin have same attributes for logging in. email and password. please help me.yes i used mysql for writing queries,using them i retrieved records of user
Sergey Alexandrovich Kryukov 3-May-16 13:11pm    
Right, you should not have separate login. You identify the user, and then you know what kind of the user is that, from your database. What's the problem?
Dheeraj Cidda 3-May-16 14:37pm    
yes sir,exactly.I want the code how to differentiate whether it is a user or admin.can u please help..
can we talk privately sir if possible please.
Sergey Alexandrovich Kryukov 3-May-16 15:20pm    
What do you mean by "want code". You are the one who is supposed to develop code, otherwise this is not the site for you. You can contact me via my Web site, but I cannot guarantee anything.

1 solution

You will have to assign different roles that come with different permissions for different users.
Get the idea from this introductory tutorial: How to make Role-Based Access Control in PHP | Sevvlor[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900