netv-mam/update.php
2024-09-03 10:37:30 -04:00

35 lines
1.2 KiB
PHP

<?php
$db = new SQLite3('netv-mam.sqlite');
// update metadata for a file by id
if (isset($_GET['id']) && $_GET['id'] !== "") {
error_log(print_r($_REQUEST, true));
$id = intval($_GET['id']);
$query = $db->prepare("SELECT * FROM media WHERE id = :id");
$query->bindValue(':id', $id);
$result = $query->execute();
if ($result) {
// record exists, update it
$update_query = $db->prepare("UPDATE media SET title=:title, description=:description, season=:season, episode_number=:episode_number WHERE id = :id");
$update_query->bindValue(':title', $_REQUEST['title']);
$update_query->bindValue(':description', $_REQUEST['description']);
$update_query->bindValue(':season', $_REQUEST['season']);
$update_query->bindValue(':episode_number', $_REQUEST['episode_number']);
$update_query->bindValue(':id', $id);
error_log($update_query->getSQL(true));
$update_result = $update_query->execute();
if ($update_result) {
$query = $db->prepare("SELECT * FROM media WHERE id = :id");
$query->bindValue(':id', $id);
$final_result = $query->execute();
if ($final_result) {
echo(json_encode($final_result->fetchArray(SQLITE3_ASSOC)));
}
}
}
}
?>