-
Notifications
You must be signed in to change notification settings - Fork 1
/
addtask.php
48 lines (38 loc) · 1.32 KB
/
addtask.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
48
<?php
class Database {
private $conn;
public function __construct($servername, $username, $password, $database) {
$this->conn = new mysqli($servername, $username, $password, $database);
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}
public function addTask($project_id, $emp_id, $role) {
$sqlInsertTask = "INSERT INTO task (project_id, emp_id, role) VALUES ('$project_id', '$emp_id', '$role')";
if ($this->conn->query($sqlInsertTask) === TRUE) {
echo '<script>';
echo 'alert("Task added successfully");';
echo 'window.location.href = "manager_dashboard.php";';
echo '</script>';
} else {
echo "Error adding task: " . $this->conn->error;
}
}
public function closeConnection() {
$this->conn->close();
}
}
// Database connection parameters
$servername = "localhost";
$username = "root";
$password = "";
$database = "project_database";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$project_id = $_POST["project_id"];
$emp_id = $_POST["emp_id"];
$role = $_POST["role"];
$db = new Database($servername, $username, $password, $database);
$db->addTask($project_id, $emp_id, $role);
$db->closeConnection();
}
?>