-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_other_user_message.php
More file actions
45 lines (35 loc) · 1.15 KB
/
get_other_user_message.php
File metadata and controls
45 lines (35 loc) · 1.15 KB
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lost_found_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$response = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$user_id = $_POST['user_id'];
$receiver_id = $_POST['receiver_id'];
$stmt = $conn->prepare("SELECT * FROM user_message WHERE (sender_id = ? AND receiver_id = ?) OR (sender_id = ? AND receiver_id = ?) ORDER BY created_at ASC");
$stmt->bind_param("iiii", $user_id, $receiver_id, $receiver_id, $user_id);
if ($stmt->execute()) {
$result = $stmt->get_result();
$messages = array();
while ($row = $result->fetch_assoc()) {
$messages[] = $row;
}
$response['success'] = true;
$response['messages'] = $messages;
} else {
$response['success'] = false;
$response['error'] = 'Failed to load messages';
}
$stmt->close();
} else {
$response['success'] = false;
$response['error'] = 'Invalid request';
}
echo json_encode($response);
$conn->close();
?>