-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_delete.php
More file actions
35 lines (28 loc) · 994 Bytes
/
user_delete.php
File metadata and controls
35 lines (28 loc) · 994 Bytes
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
<?php
session_start();
require "core/config.php";
if (!isset($_GET["username"])) {
header("location: index.php");
exit();
}
try {
$user = $connection->query("SELECT username FROM user WHERE username = '{$_GET['username']}'");
if ($user->num_rows < 1) {
header("location: index.php");
exit();
}
$connection->query("DELETE FROM user WHERE username = '{$_GET['username']}'");
$connection->query("DELETE FROM post WHERE author = '{$_GET['username']}'");
$connection->query("DELETE FROM relation WHERE from_user = '{$_GET['username']}'");
$connection->query("DELETE FROM relation WHERE to_user = '{$_GET['username']}'");
$_SESSION["message"] = "User was deleted successfully";
$_SESSION["message-type"] = "primary";
header("location: index.php");
exit();
} catch (Exception $e) {
$_SESSION["message"] = "Something went wrong";
$_SESSION["message-type"] = "danger";
header("location: index.php");
exit();
}
?>