-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_comment.php
52 lines (44 loc) · 1.29 KB
/
get_comment.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
52
<?php
// Pastikan tidak ada output sebelum JSON
error_reporting(0); // Temporary fix, better handling below
header('Content-Type: application/json');
session_start();
require('koneksi.php');
require('auth.php');
try {
if (!isset($_SESSION['role']) || ($_SESSION['role'] !== '2' && $_SESSION['role'] !== '4')) {
throw new Exception('Unauthorized');
}
$data = json_decode(file_get_contents('php://input'), true);
if (!$data) {
throw new Exception('Invalid request data');
}
$nama = $data['nama'];
$bulan = $data['bulan'];
$tahun = $data['tahun'];
$sql = "SELECT comment FROM laporan
WHERE nama = ?
AND MONTH(waktu) = ?
AND YEAR(waktu) = ?
AND status = 1
LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sii", $nama, $bulan, $tahun);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
echo json_encode([
'success' => true,
'comment' => $row['comment']
]);
} else {
throw new Exception('No comment found');
}
} catch (Exception $e) {
http_response_code(400);
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
}
$conn->close();