-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete.php
39 lines (32 loc) · 1.12 KB
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// session_start(); // Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
include 'config/db.php';
if (isset($_GET['id'])) {
$comp_id = intval($_GET['id']); // Ensure ID is an int
// Get the number of company for the specific box
$queryCount = "SELECT COUNT(*) AS comp_count FROM branches WHERE comp_id_fk = '$comp_id'";
$resultCount = mysqli_query($conn, $queryCount);
$rowCount = mysqli_fetch_assoc($resultCount);
$Count = $rowCount['comp_count'];
if ($Count > 0) {
echo 'Error: Cannot delete a Company having branches';
} else {
// Prepare and execute the delete query
$sql = "DELETE FROM `compani` WHERE `comp_id`='$comp_id'";
if ($conn->query($sql) === TRUE) {
header('Location: Companies.php');
exit(); // Make sure no further code is executed after redirect
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
}
?>