<?php
include("./include/config.php");

// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Get the data from the request
    $mobile_id = $_POST['mobile_id'];
    $sender_id = $_POST['sender_id'];
    $msg = $_POST['msg'];
    $date = $_POST['date'];

    // Prepare the SQL statement
    $sql = "INSERT INTO sms (mobile_id, sender_id, msg, date) VALUES (?, ?, ?, ?)";
    $stmt = $conn->prepare($sql);

    // Bind the parameters to the statement
    $stmt->bind_param("ssss", $mobile_id, $sender_id, $msg, $date);

    // Execute the statement
    if ($stmt->execute()) {
        // Data insertion successful
        $response = array("status" => "success", "message" => "Data inserted successfully");
        echo json_encode($response);
    } else {
        // Data insertion failed
        $response = array("status" => "error", "message" => "Failed to insert data");
        echo json_encode($response);
    }

    // Close the statement
    $stmt->close();
}

// Close the database connection
$conn->close();
?>
