<?php

// get data
$DirectorID = 0;
if(isset($_POST['DirectorID']))
    $DirectorID = $_POST['DirectorID'];

// if so return to list or give error ???
if ($DirectorID == 0)
{
    $redirect = "location: index.php";
   // header($redirect);
    exit();
    
}

// attempt to connect to the DB
$dbconn = mysqli_connect("localhost", "root", "", "moviedatabase");
if ($dbconn->connect_error > 0) {
    die('Could not connect: ' . $dbconn->connect_error);
    exit(); // you should redirect to some form of error page !!!
}

// delete Director
$sql = $dbconn->prepare("delete from director where DirectorID = ? ");
$sql->bind_param('i', $DirectorID);	
// execute the query 
$sql->execute(); 
// close the DB and connection
$sql->close();
$dbconn->close(); 

// redirect back to the list
header('Location: index.php');
 ?>


