-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
124 lines (109 loc) · 4.61 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
require_once 'php_action/db_connect.php';
session_start();
if(isset($_SESSION['userId'])){
header('location: http://localhost/stock_system/dashboard.php');
}
$errors = array();
$username = $password = '';
if($_POST) {
$username = $_POST['Username'];
$password = $_POST['Password'];
if(empty($username) || empty($password)) {
if($username == "") {
$errors['username'] = "Username is required";
}
if($password == ""){
$errors['password'] = "Password is required";
}
} else {
$sql = "SELECT * FROM users WHERE username = '$username'";
$result = $connect->query($sql);
if($result->num_rows == 1) {
// $password = $password;
//exists
$mainSql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$mainResult = $connect->query($mainSql);
if($mainResult->num_rows == 1) {
$value = $mainResult->fetch_assoc();
print_r($value);
$user_id = $value['user_id'];
//set session
$_SESSION['userId'] = $user_id;
header('location:dashboard.php');
} else {
$errors['username'] = "Incorrect username/password combination";
}
} else{
$errors['password'] = "Username does not exists";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Stock Management System</title>
<!-- bootstrap -->
<link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap.min.css">
<!-- bootstrap theme -->
<link rel="stylesheet" type="text/css" href="assets/bootstrap/css/bootstrap-theme.min.css">
<!-- font awesome -->
<link rel="stylesheet" type="text/css" href="assets/font-awesome/css/fontawesome.min.css">
<!-- custom css -->
<link rel="stylesheet" type="text/css" href="custom/css/custom.css">
<!-- jquery -->
<script type="text/javascript" src="assets/jquery/jquery.min.js"></script>
<!-- jqueryui -->
<link rel="stylesheet" type="text/css" href="assets/jquery-ui/jquery-ui.min.css"></script>
<script type="text/javascript" src="assets/jquery-ui/jquery-ui.min.js"></script>
<!-- bootstrap js -->
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row vertical">
<div class="col-md-5 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Please Sign In</h3>
</div>
<div class="panel-body">
<div class="messages">
<?php if($errors) {
foreach ($errors as $key => $value) {
echo '<div class="alert alert-warning" role="alert">
<i class="glyphicon glyphicon-exclamation-sign"></i>
'.$value.'</div>';
}
}?>
</div>
<form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" id="LoginForm">
<div class="form-group">
<label for="Username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" placeholder="Username" name="Username">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" name="Password" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submit" class="btn btn-default"> <i class="glyphicon glyphicon-log-in"></i>Sign in</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- col-md-5 -->
</div>
<!--/row -->
</div>
<!--/container-->
</body>
</html>