-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_user.php
More file actions
48 lines (39 loc) · 1.32 KB
/
delete_user.php
File metadata and controls
48 lines (39 loc) · 1.32 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
<?php
session_start();
// Include database connection
// Start session (if not already started)
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sem4";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Establish database connection (replace with your database credentials)
//$conn = mysqli_connect("localhost", "username", "password", "bm");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if ID parameter exists
if (isset($_POST["id"])) {
// Sanitize and validate ID
$id = filter_var($_POST["id"], FILTER_SANITIZE_NUMBER_INT);
// Prepare and execute SQL statement to delete user
$sql = "DELETE FROM `user_form` WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
// User deleted successfully
$_SESSION['success'] = "User deleted successfully.";
} else {
// Error occurred while deleting user
$_SESSION['error'] = "Error occurred while deleting user.";
}
// Close prepared statement
$stmt->close();
}
}
// Redirect back to user list page
header("Location: adminUserlist.php");
exit;
?>