-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
43 lines (34 loc) · 950 Bytes
/
delete.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
<?php include "connection.php" ?>
<?php
session_start();
// Logouts the user
unset($_SESSION['login']);
deleteAccount();
// Deletes the data
setcookie("unme", $username, time() - 60 * 60 * 24 * 30);
unset($_SESSION['uname']);
/**
* Deletes users
*
* @return void
*/
function deleteAccount()
{
global $con;
try {
// Prepare and binds placeholders
$query = "DELETE FROM Accounts WHERE username = ?";
$prep_delete = $con->prepare($query);
$prep_delete->bind_param("s", $username);
// Sets parameters and execute prepare statement
$username = $_SESSION["uname"];
$prep_delete->execute();
// End prepare statement
$prep_delete->close();
} catch (Exception $e) {
echo "<script>console.error('" . $e->getMessage() . "');</script>";
}
}
// Goes back to the Login page
header("Location: http://localhost/PHPatriots/login.php");
?>