-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteMsg.php
More file actions
36 lines (26 loc) · 794 Bytes
/
deleteMsg.php
File metadata and controls
36 lines (26 loc) · 794 Bytes
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
<?php
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
// Connect to database
require_once "db_config.php";
// Delete from database
$sql_query = "DELETE FROM message WHERE id = ?";
if ($stmt = mysqli_prepare($db_connection, $sql_query)) {
// Bind variables to prepared SQL statement
mysqli_stmt_bind_param($stmt, 'i', $_GET['messageId']);
// Execute SQL statement
if (mysqli_stmt_execute($stmt)) {
}
else {
echo "Cannot execute delete msg SQL query";
exit;
}
mysqli_stmt_close($stmt);
}
mysqli_close($db_connection);
header("location: {$_SERVER['HTTP_REFERER']}");
?>