-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (97 loc) · 3.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
include('includes/config.php');
$reqErr = $loginErr = "";
if($_SERVER['REQUEST_METHOD'] == "POST") {
if(!empty($_POST['txtUsername']) && !empty($_POST['txtPassword']) && isset($_POST['login_type'])){
session_start();
$username = $_POST['txtUsername'];
$password = $_POST['txtPassword'];
$_SESSION['sessLogin_type'] = $_POST['login_type'];
if($_SESSION['sessLogin_type'] == "retailer") {
//if selected type is retailer than check for valid retailer.
$query_selectRetailer = "SELECT retailer_id,username,password FROM retailer WHERE username='$username' AND password='$password'";
$result = mysqli_query($con,$query_selectRetailer);
$row = mysqli_fetch_array($result);
if($row) {
$_SESSION['retailer_id'] = $row['retailer_id'];
$_SESSION['sessUsername'] = $_POST['txtUsername'];
$_SESSION['sessPassword'] = $_POST['txtPassword'];
$_SESSION['retailer_login'] = true;
header('Location:retailer/index.php');
}
else {
$loginErr = "* Username or Password is incorrect.";
}
}
else if($_SESSION['sessLogin_type'] == "manufacturer") {
//if selected type is manufacturer than check for valid manufacturer.
$query_selectManufacturer = "SELECT man_id,username,password FROM manufacturer WHERE username='$username' AND password='$password'";
$result = mysqli_query($con,$query_selectManufacturer);
$row = mysqli_fetch_array($result);
if($row) {
$_SESSION['manufacturer_id'] = $row['man_id'];
$_SESSION['sessUsername'] = $_POST['txtUsername'];
$_SESSION['sessPassword'] = $_POST['txtPassword'];
$_SESSION['manufacturer_login'] = true;
header('Location:manufacturer/index.php');
}
else {
$loginErr = "* Username or Password is incorrect.";
}
}
else if($_SESSION['sessLogin_type'] == "admin") {
$query_selectAdmin = "SELECT username,password FROM admin WHERE username='$username' AND password='$password'";
$result = mysqli_query($con,$query_selectAdmin);
$row = mysqli_fetch_array($result);
if($row) {
$_SESSION['admin_login'] = true;
$_SESSION['sessUsername'] = $_POST['txtUsername'];
$_SESSION['sessPassword'] = $_POST['txtPassword'];
header('Location:admin/index.php');
}
else {
$loginErr = "* Username or Password is incorrect.";
}
}
}
else {
$reqErr = "* All fields are required.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Login </title>
<link rel="stylesheet" href="includes/main_style.css" >
</head>
<body class="login-box">
<h1>LOGIN</h1>
<form action="" method="POST" class="login-form">
<ul class="form-list">
<li>
<div class="label-block"> <label for="login:username">Username</label> </div>
<div class="input-box"> <input type="text" id="login:username" name="txtUsername" placeholder="Username" /> </div>
</li>
<li>
<div class="label-block"> <label for="login:password">Password</label> </div>
<div class="input-box"> <input type="password" id="login:password" name="txtPassword" placeholder="Password" /> </div>
</li>
<li>
<div class="label-block"> <label for="login:type">Login Type</label> </div>
<div class="input-box">
<select name="login_type" id="login:type">
<option value="" disabled selected>-- Select Type --</option>
<option value="retailer">Retailer</option>
<option value="manufacturer">Manufacturer</option>
<option value="admin">Admin</option>
</select>
</div>
</li>
<li>
<input type="submit" value="Login" class="submit_button" /> <span class="error_message"> <?php echo $loginErr; echo $reqErr; ?> </span>
</li>
</ul>
</form>
</body>
</html>