Skip to content

Commit ade583a

Browse files
committed
delete event
1 parent 11d8bee commit ade583a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

adm/events/delete.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
session_start();
3+
4+
if ($_SESSION['role'] != 'A') {
5+
header('Location: /');
6+
exit();
7+
}
8+
9+
require_once('../../../helpers/config.php');
10+
require_once('../../../helpers/connection.php');
11+
12+
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
13+
die('method is not allowed');
14+
}
15+
16+
if (!isset($_POST['id']) || empty($_POST['id'])) {
17+
die('please suplly valid id');
18+
}
19+
20+
if ($_POST['token'] != $_SESSION['deleteevent']) {
21+
unset($_SESSION['deleteevent']);
22+
header('Location: ./index.php?error=Invalid Token');
23+
exit();
24+
}
25+
26+
try {
27+
$query = 'DELETE FROM events WHERE id=UUID_TO_BIN(?)';
28+
$stmt = $db->prepare($query);
29+
$stmt->bind_param('s', $_POST['id']);
30+
$stmt->execute();
31+
$stmt->close();
32+
$db -> close();
33+
unset($_SESSION['deleteevent']);
34+
header('Location: ./index.php?message=Event berhasil dihapus');
35+
exit();
36+
37+
} catch(Exception $e) {
38+
unset($_SESSION['deleteevent']);
39+
header('Location: index.php?error=Event gagal dihapus: ' . $e->getMessage());
40+
exit();
41+
}

0 commit comments

Comments
 (0)