could you not do it much cleaner , personally i would do something more like this , much safer , and cleaner
<?php
// 1. Allowed 'view' values
$allowedViews = ['videoID', 'uid', 'artist', 'tracktitle', 'genre', 'videourl', 'thumbs', 'playerswflink', 'switch', 'allowaccess', 'width', 'height', 'autostart'];
$view = (isset($_GET['view']) && in_array($_GET['view'], $allowedViews, true)) ? $_GET['view'] : 'videoID';
// 2. Require valid user and video
if (!empty($_GET['id']) && isset($User->id)) {
$videoID = (int) $_GET['id']; // cast to int for safety
$userId = (int) $User->id;
try {
// 3. Insert view if not already viewed
$stmt = $DBO->prepare("
INSERT INTO video_views (user_id, video_id)
VALUES (:user_id, :video_id)
ON DUPLICATE KEY UPDATE user_id = user_id
");
$stmt->execute(['user_id' => $userId, 'video_id' => $videoID]);
// 4. If a new row was inserted, increment views
if ($stmt->rowCount() > 0) {
$updateStmt = $DBO->prepare("
UPDATE user_videos
SET views = views + 1
WHERE videoID = :video_id
");
$updateStmt->execute(['video_id' => $videoID]);
}
} catch (PDOException $e) {
error_log("DB error: " . $e->getMessage());
and then just add a simple table to the existing db?
eg
CREATE TABLE video_views (
user_id INT NOT NULL,
video_id INT NOT NULL,
PRIMARY KEY (user_id, video_id)
you could even take it further and make it ip specific though which could also be advantageous