-
Notifications
You must be signed in to change notification settings - Fork 1
/
deleteEmp.php
47 lines (37 loc) · 1.21 KB
/
deleteEmp.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
41
42
43
44
45
46
47
<?php
class Database {
private $conn;
public function __construct($servername, $username, $password, $dbname) {
$this->conn = new mysqli($servername, $username, $password, $dbname);
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}
public function deleteEmployee($emp_id) {
$sql = "DELETE FROM employee WHERE emp_id = $emp_id";
if ($this->conn->query($sql) === TRUE) {
echo '<script>';
echo 'alert("Employee deleted successfully");';
echo 'window.location.href = "hr_dashboard.php";';
echo '</script>';
} else {
echo "Error deleting employee data: " . $this->conn->error;
}
}
public function closeConnection() {
$this->conn->close();
}
}
// Database connection parameters
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project_database";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve employee ID from the form
$emp_id = $_POST["emp_id"];
$db = new Database($servername, $username, $password, $dbname);
$db->deleteEmployee($emp_id);
$db->closeConnection();
}
?>