<?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['crystalid'])) {
        $crystalid = intval($_GET['crystalid']);
    } else {
        header('Location: index.php'); // Redirect if no crystalid is provided
        exit();
    }

    // Delete the record from the Crystal table
    $query = "DELETE FROM Crystal WHERE CrystalID = $crystalid";
    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);
?>