-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
242 lines (192 loc) · 7 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
spl_autoload_register(function($class){
include "classes/$class.php";
})
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="Description" content="Enter your description here" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
<title>Title</title>
</head>
<body>
<?php $database = new Database();?>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03"
aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Login system</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav ml-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#" data-toggle="modal"
data-target="#exampleModal">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="#" data-toggle="modal" data-target="#exampleModa2">Login</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Register Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Register User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST">
<label for="Email">Email: </label>
<input type="text" name="email" class="form-control" id="email">
<label for="password">Password: </label>
<input type="password" name="password" class="form-control" id="password">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="register-btn">Register</button>
</form>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['register-btn'])){
$database->insert('register',$_POST);
}
?>
<!-- Login Modal -->
<div class="modal fade" id="exampleModa2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Login User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="" method="POST">
<label for="Email">Email: </label>
<input type="text" name="email" class="form-control" id="email">
<label for="password">Password: </label>
<input type="password" name="password" class="form-control" id="password">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="login-btn">Login</button>
</form>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['login-btn'])){
/*
$email = $_POST['email'];
$pass = $_POST['password'];
$result = $database->login($email,$pass);
*/
$result = $database->login($_POST);
}
?>
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Email</th>
<th scope="col">Pass</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$result = $database->selectAll('register');
$i = 0;
foreach ($result as $row){
$i++;
?>
<tr>
<td><?php echo $i?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['pass']?></td>
<td>
<!-----------------------------------######################################################################---------------->
<form action="index.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id'] ?>">
<button class="btn btn-info edit-btn" id="<?php echo $row['id']?>" name="edit-btn">Edit</button>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
if(isset($_POST["edit-btn"])){
echo '<div id="edit-form" class="bg-warning mx-auto p-4 w-75">';
echo"<h2>Update User</h2>";
$id= $_POST['id'];
$result = $database->selectByid('register',$id);
foreach($result as $row){
$id = $row['id'];
$email = $row['email'];
$pass = $row['pass'];
?>
<form action="" method="POST">
<input type="hidden" name="update-id" value="<?php echo $id?>">
<label for="Email">Email: </label>
<input type="text" name="email" class="form-control" id="email" value="<?php echo $email?>">
<label for="password">Password: </label>
<input type="text" name="password" class="form-control" id="password" value="<?php echo $pass?>">
<br>
<button type="submit" class="btn btn-info" name="update-btn">Update</button>
<a href="index.php" class="btn btn-danger mr-auto">Cancel</a>
</form>
<?php
}
echo" </div>";
}
?>
<?php
if(isset($_POST['update-btn'])){
$id = $_POST['update-id'];
$update= $database->updateByid('register',$id);
if($update==true){
echo "<p>Update success</p>";
}
}
?>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script>
<script>
/*
$(document).ready(function () {
$(".edit-btn").click(function (e) {
// e.preventDefault();
// $("#edit-form").css("display","block");
// var editid = $(this).attr("id");
/// alert(editid);
// $('#editModel').modal('hide');
})
})
*/
</script>
</body>
</html>