This repository has been archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_quote.php
executable file
·57 lines (40 loc) · 1.71 KB
/
delete_quote.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
48
49
50
51
52
53
54
55
56
57
<?php
define('TITLE', 'Delete a Quote');
include('templates/header.html');
print '<h2>Delete a Quotation</h2>';
if (!is_administrator()) {
print '<h2>Access Denied!</h2><p class="error">You do not have permission to access this page.</p>';
include('templates/footer.html');
exit();
}
include('../mysqli_connect.php');
if (isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0) ) {
$query = "SELECT quote, source, favorite FROM quotes WHERE id={$_GET['id']}";
if ($result = mysqli_query($dbc, $query)) {
$row = mysqli_fetch_array($result);
print '<form action="delete_quote.php" method="post">
<p>Are you sure you want to delete this quote?</p>
<div><blockquote>' . $row['quote'] . '</blockquote>- ' . $row['source'];
if ($row['favorite'] == 1) {
print ' <strong>Favorite!</strong>';
}
print '</div><br><input type="hidden" name="id" value="' . $_GET['id'] . '">
<p><input type="submit" name="submit" value="Delete this Quote!"></p>
</form>';
} else {
print '<p class="error">Could not retrieve the quote because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} elseif (isset($_POST['id']) && is_numeric($_POST['id']) && ($_POST['id'] > 0) ) { // Handle the form.
$query = "DELETE FROM quotes WHERE id={$_POST['id']} LIMIT 1";
$result = mysqli_query($dbc, $query);
if (mysqli_affected_rows($dbc) == 1) {
print '<p>The quote entry has been deleted.</p>';
} else {
print '<p class="error">Could not delete the blog entry because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>';
}
} else {
print '<p class="error">This page has been accessed in error.</p>';
}
mysqli_close($dbc);
include('templates/footer.html');
?>