-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_message_to_user.php
More file actions
39 lines (31 loc) · 1007 Bytes
/
send_message_to_user.php
File metadata and controls
39 lines (31 loc) · 1007 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
<?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') {
$sender_id = $_POST['sender_id'];
$receiver_id = $_POST['receiver_id'];
$message = $_POST['message'];
$created_at = date('Y-m-d H:i:s');
$stmt = $conn->prepare("INSERT INTO user_message (sender_id, receiver_id, message, created_at) VALUES (?, ?, ?, ?)");
$stmt->bind_param("iiss", $sender_id, $receiver_id, $message, $created_at);
if ($stmt->execute()) {
$response['success'] = true;
} else {
$response['success'] = false;
$response['error'] = 'Failed to send message';
}
$stmt->close();
} else {
$response['success'] = false;
$response['error'] = 'Invalid request';
}
echo json_encode($response);
$conn->close();
?>