<?php 
if (isset($_GET['deleteFilm'])) {
    
$filmId intval($_GET['deleteFilm']);

    
// Check if this film is linked to any Plage
    
$checkStmt $LINK->prepare("SELECT COUNT(*) FROM CinePlages WHERE fk_film = ?");
    
$checkStmt->bind_param('i'$filmId);
    
$checkStmt->execute();
    
$checkStmt->bind_result($count);
    
$checkStmt->fetch();
    
$checkStmt->close();

    if (
$count 0) {
        echo 
"<p style='color:red;'>Cannot delete film: It is linked to a Plage.</p>";
        
        echo 
"<a href='?Film'><button type='button'>Go Back</button></a>";

    } else {
        
// Safe to delete
        
$deleteStmt $LINK->prepare("DELETE FROM CineFilms WHERE pk_film = ?");
        
$deleteStmt->bind_param('i'$filmId);
        
$deleteStmt->execute();
        
$deleteStmt->close();
        echo 
"<p style='color:green;'>Film deleted successfully.</p>";

        
// Optional redirect to refresh the list
        
header("Location: ?Film");
        exit();
    }
}
?>