Mini Kabibi Habibi
<?php
session_start();
@include 'include/config.php';
// Check if the user is logged in
if (!isset($_SESSION['username_school'])) {
header('Location: login.php');
exit();
}
// Get the username from session
$username = $_SESSION['username_school'];
// Validate and get the plan_id from the query string
if (!isset($_GET['report_id']) || !is_numeric($_GET['report_id'])) {
die("Invalid request.");
}
$report_id = intval($_GET['report_id']);
// First, verify ownership: ensure the logged-in user owns this record
$stmt = $conn->prepare("SELECT * FROM mqcais_reports WHERE id = ? AND username = ?");
$stmt->bind_param("is", $report_id, $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
die("Record not found or you do not have permission to delete it.");
}
// Proceed with deletion
$delete_stmt = $conn->prepare("DELETE FROM mqcais_reports WHERE id = ?");
$delete_stmt->bind_param("i", $report_id);
if ($delete_stmt->execute()) {
// Redirect after deletion
header("Location: view_mqcais_reports.php?msg=deleted");
exit();
} else {
echo "Error deleting record: " . $conn->error;
}
?>