-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.php
More file actions
59 lines (50 loc) · 1.67 KB
/
Copy pathdelete.php
File metadata and controls
59 lines (50 loc) · 1.67 KB
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
<?php
session_start();
include 'functions.php';
$pdo = pdo_connect_mysql();
$msg = '';
if (isset($_GET['id'])) {
$stmt = $pdo->prepare('SELECT * FROM polls WHERE id = ?');
$stmt->execute([$_GET['id']]);
$poll = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$poll) {
die('Poll doesn\'t exist with that ID!');
}
if ($_SESSION['id'] != $poll['creator_id'] || !$_SESSION['su']) {
$_SESSION['msg'] = "You're not the creator of this poll!";
header('Location: index.php');
exit;
}
// Make sure the user confirms before deletion
if (isset($_GET['confirm'])) {
if ($_GET['confirm'] == 'yes') {
$stmt = $pdo->prepare('DELETE FROM polls WHERE id = ?');
$stmt->execute([$_GET['id']]);
// We also need to delete the answers for that poll
$stmt = $pdo->prepare('DELETE FROM poll_answers WHERE poll_id = ?');
$stmt->execute([$_GET['id']]);
$msg = 'You have deleted the poll!';
} else {
// User clicked the "No" button, redirect them back to the home/index page
header('Location: index.php');
exit;
}
}
} else {
die('No ID specified!');
}
?>
<?=template_header('Delete')?>
<div class="container-fluid content delete">
<h2>Delete Poll #<?=$poll['id']?></h2>
<?php if ($msg): ?>
<p><?=$msg?></p>
<?php else: ?>
<p>Are you sure you want to delete poll #<?=$poll['id']?>?</p>
<div class="yesno">
<a href="delete.php?id=<?=$poll['id']?>&confirm=yes">Yes</a>
<a href="delete.php?id=<?=$poll['id']?>&confirm=no">No</a>
</div>
<?php endif;?>
</div>
<?=template_footer()?>