I have a login screen that can authenticate "users" on my web app. But i also want to reuse the same login for "customers". Its an e-commerce type of web application. I am using PHP and MYSQL mainly to do my login authentication using one table.Below is my current code for verifying "users":
//Query statement for selecting details from database
$Sql = "SELECT * FROM users WHERE email = '".$user_name."' AND password = '".$password."'";
Leaving coding part on your just demonstrating login in short. create column user_type in the users table.
Method 1: -
$Sql = "SELECT * FROM users WHERE email = '".$user_name."' AND password = '".$password."'";
if($sql['user_type']=="customer"){
$sql2 = "select * from customers";
}
now use session to store customer fields.
You can also redirect to different pages
if( $user == 1){ //check if user or password is correct from query
if($user_type == "customer"){ //check usertype
header("Location:/application/app.php"); //if normal user redirect to app.php
}else{
header("Location:/administration/admin.php"); //if admin user redirect to admin.php
}
}
Thanks for the comments. I really appreciate. After searching for a solution i found something. Here is the link to a youtube video: https://youtu.be/xlhwC6MpwOg The code can be downloaded here: https://drive.google.com/file/d/0B2lDcH-bC82deENfMHhCVF9BTHc/view