<?php
    // Attempt to connect to the database
    $dbconn = mysqli_connect("localhost", "root", "", "PannotinaCoDB");
    if ($dbconn->connect_error) {
        header('Location: error.php');
        exit();
    }


    if (isset($_GET['colourid'])) {
        $colourid = intval($_GET['colourid']);
    } else {
        header('Location: index.php'); // Redirect if no colourid is provided
        exit();
    }

    // Delete the record from the Colour table
    $query = "DELETE FROM Colour WHERE ColourID = $colourid";
    if (mysqli_query($dbconn, $query)) {
        header('Location: index.php'); // Redirect to the index page on success
    } else {
        echo "Error: " . $query . "<br>" . mysqli_error($dbconn); // Display SQL error
    }

    // Close the database connection
    mysqli_close($dbconn);
?>