prepare(" INSERT INTO youtube_videos (title, description, video_id, status, created_at) VALUES (?, ?, ?, ?, NOW()) "); $stmt->execute([$title, $description, $video_id, $status]); $message = 'YouTube video/short added successfully!'; } else { $stmt = $db->prepare(" UPDATE youtube_videos SET title = ?, description = ?, video_id = ?, status = ? WHERE id = ? "); $stmt->execute([$title, $description, $video_id, $status, $id]); $message = 'YouTube video/short updated successfully!'; } $action = 'list'; } catch (Exception $e) { $error = 'Error: ' . $e->getMessage(); } break; case 'delete': try { $delete_id = $_POST['id']; $stmt = $db->prepare("DELETE FROM youtube_videos WHERE id = ?"); $stmt->execute([$delete_id]); $message = 'YouTube video/short deleted successfully!'; } catch (Exception $e) { $error = 'Error deleting video/short: ' . $e->getMessage(); } break; } } } // Get video data for editing $video_data = null; if ($action === 'edit' && $id > 0) { $stmt = $db->prepare("SELECT * FROM youtube_videos WHERE id = ?"); $stmt->execute([$id]); $video_data = $stmt->fetch(); if (!$video_data) { $error = 'Video/short not found!'; $action = 'list'; } } // Get videos list $videos_list = []; if ($action === 'list') { $stmt = $db->prepare("SELECT * FROM youtube_videos ORDER BY created_at DESC"); $stmt->execute(); $videos_list = $stmt->fetchAll(); } include 'includes/header.php'; ?>