<?php
include '../config/config.php';
session_start();
if(isset($_POST['watch_time'])) {
    $uid = $_SESSION['user_id'];
    $did = (int)$_POST['drama_id'];
    $eid = (int)$_POST['episode_id'];
    $sec = (int)$_POST['watch_time'];

    // Update or Insert the watch time
    $sql = "INSERT INTO ratings (user_id, drama_id, episode_id, watch_time_seconds, score) 
            VALUES (?, ?, ?, ?, 0) 
            ON DUPLICATE KEY UPDATE watch_time_seconds = watch_time_seconds + 30";
    $pdo->prepare($sql)->execute([$uid, $did, $eid, $sec]);
}
?>