-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogprocess.php
80 lines (34 loc) · 1.3 KB
/
logprocess.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
<?php
// include('config.php');
$servername = "localhost"; //My server
$username = "root";
$password = ""; // No password
$dbname = "Cafedb"; //Name of database
//create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
session_start();
if (isset($_POST['login'])) {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, md5($_POST["password"]));
$query = "SELECT * FROM register WHERE username= '$username' AND passwords= '$password'";
$result = mysqli_query($conn,$query);
if (mysqli_num_rows($result) == 1) {
echo "<script>alert('You are good to go')</script>";
$role = "SELECT roles FROM register WHERE username= '$username' AND passwords='$password'";
$roles = mysqli_query($conn, $role);
$row = mysqli_fetch_array($roles);
if ($row['roles'] == "Admin") {
$_SESSION['Admin'] = $username;
header("Location:admin.php");
}
else if($row['roles'] == "User") {
$_SESSION['User'] = $username;
header("Location:user.php");
}
}
else{
echo "<script>alert('Invalid account')</script>";
header("Location:register.php");
}
}
?>