Mini Kabibi Habibi

Current Path : C:/xampp/htdocs/cid/system/
Upload File :
Current File : C:/xampp/htdocs/cid/system/delete_schedule.php

<?php
session_start();
@include 'include/config.php';

// Check if user is logged in
if (!isset($_SESSION['username_school'])) {
    header("Location: login.php");
    exit();
}

$username = $_SESSION['username_school'];

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    // Verify that the schedule belongs to the logged-in user before deleting
    $stmt = $conn->prepare("DELETE FROM schedule WHERE id = ? AND username = ?");
    $stmt->bind_param("is", $id, $username);

    if ($stmt->execute()) {
        $_SESSION['success'] = "Schedule deleted successfully.";
    } else {
        $_SESSION['error'] = "Failed to delete schedule.";
    }

    $stmt->close();
} else {
    $_SESSION['error'] = "Invalid request.";
}

// Redirect back to the user's schedule list
header("Location: user_index.php");
exit();
?>