-
Notifications
You must be signed in to change notification settings - Fork 1
/
editNoticehr.php
51 lines (41 loc) · 1.33 KB
/
editNoticehr.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
51
<?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 addNotice($notice) {
$sqlInsertNotice = "INSERT INTO notice (time, notice) VALUES (CURRENT_TIME(), '$notice')";
if ($this->conn->query($sqlInsertNotice) === TRUE) {
return true;
} else {
return false;
}
}
public function closeConnection() {
$this->conn->close();
}
}
// Database connection parameters
$servername = "localhost";
$username = "root";
$password = "";
$database = "project_database";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$notice = $_POST["notice"];
$db = new Database($servername, $username, $password, $database);
if ($db->addNotice($notice)) {
// echo "<script>alert('Notice submitted successfully');</script>",
echo '<script>';
echo 'alert("Notice submitted successfully");';
echo 'window.location.href = "hr_dashboard.php";';
echo '</script>';
} else {
echo "Error submitting notice: " . $conn->error;
}
$db->closeConnection();
}
?>