-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
47 lines (36 loc) · 1005 Bytes
/
functions.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
<?php
/* GET functions */
$id = '';
$fname = '';
$lname = '';
$username = '';
$email = '';
$update = false;
$_SESSION['message'] = '';
$_SESSION['toggle'] = '';
// Delete function
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$sqlDelete = "DELETE FROM users WHERE id=$id";
$deleted = mysqli_query($connection, $sqlDelete) or die(mysqli_error($connection));
if ($deleted) {
$_SESSION['message'] = 'User deleted successfully';
$_SESSION['toggle'] = 'warning';
header('location:index.php');
}
}
// Edit function
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$sqlFetch = "SELECT * FROM users WHERE id=$id LIMIT 1";
$result = mysqli_query($connection, $sqlFetch);
if (mysqli_num_rows($result) == 1) {
$update = true;
$row = mysqli_fetch_array($result);
$id = $row['id'];
$fname = $row['firstname'];
$lname = $row['lastname'];
$username = $row['username'];
$email = $row['email'];
}
}