Mini Kabibi Habibi

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

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

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

$username = $_SESSION['username'];

// Check if ID is passed
if (!isset($_GET['id'])) {
    $_SESSION['error'] = "No record selected to delete.";
    header('Location: daily_accomplishments.php');
    exit();
}

$id = intval($_GET['id']);

// Delete only if the record belongs to the logged-in user
$check = mysqli_query($conn, "SELECT * FROM daily_accomplishments WHERE id = $id AND username = '$username'");

if (mysqli_num_rows($check) === 0) {
    $_SESSION['error'] = "Record not found or you do not have permission to delete it.";
    header('Location: daily_accomplishments.php');
    exit();
}

$delete = mysqli_query($conn, "DELETE FROM daily_accomplishments WHERE id = $id AND username = '$username'");

if ($delete) {
    $_SESSION['success'] = "Record deleted successfully.";
} else {
    $_SESSION['error'] = "Failed to delete record: " . mysqli_error($conn);
}

header('Location: daily_accomplishments.php');
exit();
?>