-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
49 lines (41 loc) · 1.4 KB
/
api.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
include('config.php');
// Set the content type to JSON
header('Content-Type: application/json');
// Retrieve the 'discord_id' from the query parameters
$discord_id = filter_input(INPUT_GET, 'discord_id', FILTER_SANITIZE_STRING);
if (!$discord_id) {
echo json_encode([
'error' => 'Discord ID is required'
]);
exit;
}
try {
// Prepare the SQL query to fetch the record
$stmt = $pdo->prepare("SELECT discord_id, discord_username, steam_id, console_id, reason, timestamp FROM submissions WHERE discord_id = ? AND approved=1;");
$stmt->execute([$discord_id]);
// Fetch the record from the database
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
// If the record exists, return it as a JSON object
$date = new DateTime($row['timestamp']);
echo json_encode([
'Discord ID' => (string)$row['discord_id'],
'Discord Username' => $row['discord_username'],
'Steam ID' => $row['steam_id'],
'Console ID' => $row['console_id'],
'Reason' => $row['reason'],
'Timestamp' => $date->format(DateTime::RFC3339)
]);
} else {
// If no record exists, return an error message
echo json_encode([
]);
}
} catch (PDOException $e) {
// If there is a database error, return the error message
echo json_encode([
'error' => 'Database error: ' . $e->getMessage()
]);
}
?>