38497-vm/api/log_session.php
Flatlogic Bot 688e42d5dc v1
2026-02-16 19:45:52 +00:00

46 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
require_once __DIR__ . '/../includes/db.php';
header('Content-Type: application/json');
$response = ['success' => false, 'message' => '', 'error' => ''];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = file_get_contents('php://input');
$data = json_decode($input, true);
$patternName = $data['pattern_name'] ?? null;
$intensity = $data['intensity'] ?? null;
$durationSeconds = $data['duration_seconds'] ?? null;
if ($patternName === null || $intensity === null || $durationSeconds === null) {
$response['error'] = 'Missing required parameters.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare(
'INSERT INTO massage_sessions (pattern_name, intensity, duration_seconds) VALUES (:pattern_name, :intensity, :duration_seconds)'
);
$stmt->bindParam(':pattern_name', $patternName);
$stmt->bindParam(':intensity', $intensity, PDO::PARAM_STR); // Use PARAM_STR for float to avoid precision issues
$stmt->bindParam(':duration_seconds', $durationSeconds, PDO::PARAM_INT);
$stmt->execute();
$response['success'] = true;
$response['message'] = 'Session logged successfully.';
} catch (PDOException $e) {
$response['error'] = 'Database error: ' . $e->getMessage();
} catch (Exception $e) {
$response['error'] = 'Server error: ' . $e->getMessage();
}
}
} else {
$response['error'] = 'Invalid request method.';
}
echo json_encode($response);