-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_user.php
40 lines (32 loc) · 1.02 KB
/
delete_user.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
<?php
// Include your database configuration here
$servername = "localhost";
$username = "Atharav";
$password = "Atharav@31";
$dbname = "project";
// Check if the 'id' parameter is set in the URL
if (isset($_GET['id'])) {
$user_id = $_GET['id'];
// Function to delete a user by ID
function deleteUserById($id) {
global $servername, $username, $password, $dbname;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DELETE FROM users WHERE id = $id";
if ($conn->query($sql) === TRUE) {
// Redirect back to action.php with a success message
header("Location: action.php?delete=success");
exit();
} else {
echo "Error deleting user: " . $conn->error;
}
$conn->close();
}
// Call the function to delete the user
deleteUserById($user_id);
} else {
echo "User ID not provided.";
}
?>