Mini Kabibi Habibi
<?php
session_start(); // Start the session
include 'db_connection.php'; // Include the database connection
// Check if the user is logged in, and if not, redirect to login page
if (!isset($_SESSION['username'])) {
header("Location: index.php"); // Redirect to login page if user is not logged in
exit();
}
// Check if an ID is provided via the URL
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Prepare and execute the DELETE query to remove the inventory record
$sql = "DELETE FROM submitted_inventory WHERE id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'i', $id); // Bind the ID parameter
$delete_success = mysqli_stmt_execute($stmt); // Execute the delete query
// Check if the deletion was successful
if ($delete_success) {
$_SESSION['success_message'] = "Inventory deleted successfully!"; // Success message
} else {
$_SESSION['error_message'] = "There was an error deleting the inventory."; // Error message
}
// Redirect back to the inventory view page after the operation
header("Location: school_dashboard.php"); // You can change this to the appropriate page
exit();
} else {
// If no ID is provided, display an error message
$_SESSION['error_message'] = "No ID provided for deletion.";
header("Location: view_inventory.php");
exit();
}
?>