-
Notifications
You must be signed in to change notification settings - Fork 1
/
addProj.php
50 lines (40 loc) · 1.58 KB
/
addProj.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
49
50
<?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 addProject($project_id, $project_name, $description, $starting_date, $ending_date) {
$sql = "INSERT INTO project (project_id, project_name, description, starting_date, ending_date)
VALUES ('$project_id', '$project_name', '$description', '$starting_date', '$ending_date')";
if ($this->conn->query($sql) === TRUE) {
echo '<script>';
echo 'alert("Project added successfully");';
echo 'window.location.href = "hr_dashboard.php";';
echo '</script>';
} else {
echo "Error adding project: " . $this->conn->error;
}
}
public function closeConnection() {
$this->conn->close();
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$project_id = $_POST["project_id"];
$project_name = $_POST["project_name"];
$description = $_POST["description"];
$starting_date = $_POST["starting_date"];
$ending_date = $_POST["ending_date"];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project_database";
$db = new Database($servername, $username, $password, $dbname);
$db->addProject($project_id, $project_name, $description, $starting_date, $ending_date);
$db->closeConnection();
}
?>