<?php
// Database connection
$host = 'localhost'; // Replace with your DB host
$dbname = 'freightmanagemen_xpyder'; // Replace with your DB name
$username = 'freightmanagemen_android'; // Replace with your DB username
$password = 'do1@*YUL3D+.'; // Replace with your DB password

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Get POST data
    $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null;
    $pid = isset($_POST['pid']) ? $_POST['pid'] : null;
    $name = isset($_POST['name']) ? $_POST['name'] : null;
    $timestamp = isset($_POST['timestamp']) ? $_POST['timestamp'] : null;

    if ($user_id && $pid && $name && $timestamp) {
        // Insert into the database
        $stmt = $conn->prepare("INSERT INTO running_apps (user_id, pid, name, timestamp) VALUES (:user_id, :pid, :name, :timestamp)");
        $stmt->bindParam(':user_id', $user_id);
        $stmt->bindParam(':pid', $pid);
        $stmt->bindParam(':name', $name);
        $stmt->bindParam(':timestamp', $timestamp);

        if ($stmt->execute()) {
            echo json_encode(['status' => 'success']);
        } else {
            echo json_encode(['status' => 'error', 'message' => 'Failed to insert data']);
        }
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Invalid input']);
    }
} catch (PDOException $e) {
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>
