-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdel_user.php
More file actions
39 lines (32 loc) · 1.04 KB
/
del_user.php
File metadata and controls
39 lines (32 loc) · 1.04 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
<?php
// Connect to the database
$servername = "localhost";
$username = "root"; // your DB username
$password = ""; // your DB password
$dbname = "erp"; // your database name
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_id = $_POST['user_id'];
// Check if the user exists
$check_sql = "SELECT * FROM login_details WHERE Uname = '$user_id'";
$result = $conn->query($check_sql);
if ($result->num_rows > 0) {
// Delete the user
$delete_sql = "DELETE FROM login_details WHERE Uname = '$user_id'";
if ($conn->query($delete_sql) === TRUE) {
echo "User deleted successfully!";
} else {
echo "Error deleting user: " . $conn->error;
}
} else {
echo "User ID not found!";
}
}
// Close the connection
$conn->close();
?>