-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemp_server.php
48 lines (40 loc) · 1.27 KB
/
emp_server.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
<?php
session_start();
// initializing variables
$emp_name = "";
$emp_email = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'root', '', 'spartanshub');
// LOGIN USER
if (isset($_POST['login_user'])) {
$emp_name = mysqli_real_escape_string($db, $_POST['emp_name']);
$pass = mysqli_real_escape_string($db, $_POST['emp_pass']);
if (empty($emp_name)) {
array_push($errors, "Username is required");
}
if (empty($pass)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$emp_pass = md5('emp_pass');
$query = "SELECT * FROM employee_reg WHERE emp_name='$emp_name' AND emp_pass='$emp_pass'";
$results = mysqli_query($db, $query);
$row = mysqli_fetch_array($results);
if (mysqli_num_rows($results) == 1) {
$_SESSION['emp_name'] = $emp_name;
foreach ($row as $key => $value){
if(is_string($key)) {
$_SESSION [$key]= $value;
//echo $key. ":".$value."<br>";
}
}
echo $_SESSION['emp_email'];
$_SESSION['success'] = "You are now logged in";
header('location: ./employee/dashboard.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
?>