false, 'error' => 'Invalid video ID']); exit; } try { $stmt = $pdo->prepare("UPDATE videos SET views = views + 1 WHERE id = ?"); $stmt->execute([$video_id]); // Log the play event $v_stmt = $pdo->prepare("SELECT title FROM videos WHERE id = ?"); $v_stmt->execute([$video_id]); $title = $v_stmt->fetchColumn(); logEvent('play', "Started watching: $title (ID: $video_id)"); echo json_encode(['success' => true]); } catch (Exception $e) { echo json_encode(['success' => false, 'error' => 'Database error']); } ?>