37705-vm/add_session.php
Flatlogic Bot f96cd48907 v1
2026-01-22 13:33:07 +00:00

26 lines
806 B
PHP

<?php
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$start_time = $_POST['start_time'] ?? '';
$end_time = $_POST['end_time'] ?? '';
$rating = isset($_POST['rating']) ? (int)$_POST['rating'] : null;
if ($start_time && $end_time) {
try {
$stmt = db()->prepare("INSERT INTO sleep_sessions (start_time, end_time, rating) VALUES (?, ?, ?)");
$stmt->execute([$start_time, $end_time, $rating]);
header('Location: index.php?success=1');
exit;
} catch (PDOException $e) {
die("Error saving session: " . $e->getMessage());
}
} else {
header('Location: index.php?error=missing_fields');
exit;
}
} else {
header('Location: index.php');
exit;
}