-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_message.php
More file actions
119 lines (98 loc) · 3.55 KB
/
delete_message.php
File metadata and controls
119 lines (98 loc) · 3.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
session_start(); // Start the session.
// If no session value is present, redirect the user:
if (!isset($_SESSION['employee_id'])) {
require_once ('includes/login_functions.inc.php');
$url = absolute_url('login.php');
header("Location: $url");
exit();
}
$page_title = 'Delete a User';
include ('includes/header.html');
echo '<div id="content">
<div class="container">
<div class="inside">
<!-- box begin -->
<div class="box alt">
<div class="left-top-corner">
<div class="right-top-corner">
<div class="border-top"></div>
</div>
</div>
<div class="border-left">
<div class="border-right">
<div class="inner">
<div class="wrapper">
<h3>Delete Messages</h3>';
// Check for a valid user ID, through GET or POST:
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error.</p>';
include ('includes/footer.html');
exit();
}
require_once ('../mysqli_connect.php');
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
if ($_POST['sure'] == 'Yes') { // Delete the record.
// Make the query:
$q = "DELETE FROM contactus WHERE contact_id=$id LIMIT 1";
$r = @mysqli_query ($dbc, $q);
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
// Print a message:
echo '<p>The message has been deleted.</p>';
} else { // If the query did not run OK.
echo '<p class="error">The message could not be deleted due to a system error.</p>'; // Public message.
echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
}
} else { // No confirmation of deletion.
//echo '<p>The message has NOT been deleted.</p>';
// Redirect:
$url = absolute_url ('message.php');
header("Location: $url");
exit();
}
} else { // Show the form.
// Retrieve the message's information:
$q = "SELECT CONCAT(last_name, ', ', first_name) FROM contactus WHERE contact_id=$id";
$r = @mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Valid message ID, show the form.
// Get the message's information:
$row = mysqli_fetch_array ($r, MYSQLI_NUM);
// Create the form:
echo '<form action="delete_user.php" method="post">
<h3>Name: ' . $row[0] . '</h3>
<p>Are you sure you want to delete this message?<br />
<input type="radio" name="sure" value="Yes" /> Yes
<input type="radio" name="sure" value="No" checked="checked" /> No</p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';
} else { // Not a valid message ID.
echo '<p class="error">This page has been accessed in error.</p>';
}
} // End of the main submission conditional.
mysqli_close($dbc);
echo ' <dl class="special fright">
</div>
</div>
</div>
</div>
<div class="left-bot-corner">
<div class="right-bot-corner">
<div class="border-bot"></div>
</div>
</div>
</div>
<!-- box end -->
<!--Recent articles list ends -->
</div>
</div>
</div>
';
include ('includes/footer.html');
?>