35311-vm/save_check_in.php
2025-10-30 00:25:31 +00:00

35 lines
1.0 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: resident_dashboard.php');
exit;
}
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'resident') {
header('HTTP/1.1 403 Forbidden');
exit("Access denied.");
}
$resident_id = isset($_POST['resident_id']) ? (int)$_POST['resident_id'] : 0;
$mood_rating = isset($_POST['mood_rating']) ? (int)$_POST['mood_rating'] : 0;
$journal_entry = isset($_POST['journal_entry']) ? trim($_POST['journal_entry']) : '';
if ($resident_id === 0 || $mood_rating === 0) {
header("Location: resident_dashboard.php?error=checkin_failed");
exit;
}
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO check_ins (resident_id, mood_rating, journal_entry) VALUES (?, ?, ?)");
$stmt->execute([$resident_id, $mood_rating, $journal_entry]);
header("Location: resident_dashboard.php?success=checkin_saved");
exit;
} catch (PDOException $e) {
header("Location: resident_dashboard.php?error=checkin_failed");
exit;
}