-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMessages.php
More file actions
35 lines (27 loc) · 942 Bytes
/
getMessages.php
File metadata and controls
35 lines (27 loc) · 942 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
<?php
include 'connection.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$otherUser = isset($_GET['otherName']) ? $_GET['otherName'] : '';
if ($otherUser !== "") {
$sql = "SELECT chatContent FROM chatTable WHERE username='$otherUser'";
$result = $conn->query($sql);
if ($result !== false) {
// Fetch the data from the result set
$row = $result->fetch_assoc();
if ($row !== null) {
// Output the chat content
echo json_encode(['chatContent' => $row['chatContent']]);
} else {
echo "No messages found for the specified name.";
}
} else {
echo "Database error: " . $conn->error;
}
} else {
echo "Please enter a name to listen to.";
}
// Debugging line
}
?>