-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreminder_count.php
More file actions
48 lines (32 loc) · 920 Bytes
/
reminder_count.php
File metadata and controls
48 lines (32 loc) · 920 Bytes
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
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "coursework";
if (!isset($_SESSION['User_id'])) {
echo json_encode(["status" => "error", "message" => "Unauthorized"]);
exit();
}
$userId = intval($_SESSION['User_id']);
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
http_response_code(500);
echo "Database connection failed: " . $conn->connect_error;
exit();
}
$sql = "SELECT COUNT(*) AS reminder_count FROM reminder WHERE Reminder_status = 'Pending'AND User_id='$userId'";
$result = $conn->query($sql);
if (!$result) {
http_response_code(500);
echo "Query error: " . $conn->error;
$conn->close();
exit();
}
$row = $result->fetch_assoc();
$count = $row['reminder_count'] ?? 0;
echo $count;
$conn->close();
?>