i cant log in on admin dashboard please provide the complete code 
reference

database :
-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Sep 27, 2024 at 03:25 PM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `city_inventory_app`
--

-- --------------------------------------------------------

--
-- Table structure for table `admin_users`
--

CREATE TABLE `admin_users` (
  `id` int(11) NOT NULL,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `admin_users`
--

INSERT INTO `admin_users` (`id`, `username`, `password`) VALUES
(2, 'mpr', '$2y$10$e0NRVv1FbGn/UJX0pqkBGe3OYtj4xIUBvSXh06h4tWTJrzbcZ1p5a');

-- --------------------------------------------------------

--
-- Table structure for table `cities`
--

CREATE TABLE `cities` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `cities`
--

INSERT INTO `cities` (`id`, `name`) VALUES
(3, 'Egaleo'),
(1, 'Glyfada');

-- --------------------------------------------------------

--
-- Table structure for table `items`
--

CREATE TABLE `items` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `city_id` int(11) DEFAULT NULL,
  `current_year_quantity` int(11) DEFAULT 0,
  `prev_year_1_quantity` int(11) DEFAULT 0,
  `prev_year_2_quantity` int(11) DEFAULT 0,
  `prev_year_3_quantity` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `city_id` int(11) DEFAULT NULL,
  `approved` tinyint(1) DEFAULT 0,
  `is_admin` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `city_id`, `approved`, `is_admin`) VALUES
(1, 'pan', '$2y$10$WVkzA8.mWxvAUC04pe7woeYMcrWOLe6qSvqr46KvCtbBs.w7R2lyq', 1, 1, 0);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `admin_users`
--
ALTER TABLE `admin_users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`);

--
-- Indexes for table `cities`
--
ALTER TABLE `cities`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `name` (`name`);

--
-- Indexes for table `items`
--
ALTER TABLE `items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `city_id` (`city_id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`),
  ADD KEY `city_id` (`city_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `admin_users`
--
ALTER TABLE `admin_users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `cities`
--
ALTER TABLE `cities`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `items`
--
ALTER TABLE `items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `items`
--
ALTER TABLE `items`
  ADD CONSTRAINT `items_ibfk_1` FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`);

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

dasboard_admin:
<?php
// dashboard_admin.php

session_start();
include 'functions.php';

// Check if admin is logged in
if (isset($_GET['logout'])) {
    session_destroy();
    header("Location: dashboard_admin.php");
    exit();
}

if (!isset($_SESSION['admin_logged_in']) || !$_SESSION['admin_logged_in']) {
    // Handle login submission
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['username'])) {
        $username = $_POST['username'];
        $password = $_POST['password'];
    
        if (adminLogin($username, $password)) {
            $_SESSION['admin_logged_in'] = true;
            header("Location: dashboard_admin.php");
            exit();
        } else {
            $error = "Invalid login credentials.";
        }
    }
    
    // Display login form
    echo renderAdminLogin(isset($error) ? $error : '');
    exit();
}

// Handle AJAX requests
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action'])) {
    $response = ['status' => 'error', 'message' => 'Invalid request'];
    header('Content-Type: application/json');

    $action = $_POST['action'];

    if ($action == 'approve_user') {
        $user_id = intval($_POST['user_id']);
        if (approveUser($user_id)) {
            $response = ['status' => 'success', 'message' => 'User approved successfully.'];
        } else {
            $response = ['status' => 'error', 'message' => 'Failed to approve user.'];
        }
    } elseif ($action == 'delete_user') {
        $user_id = intval($_POST['user_id']);
        if (deleteUser($user_id)) {
            $response = ['status' => 'success', 'message' => 'User deleted successfully.'];
        } else {
            $response = ['status' => 'error', 'message' => 'Failed to delete user.'];
        }
    } elseif ($action == 'add_city') {
        $city_name = $_POST['city_name'];
        if (!empty($city_name)) {
            $city_id = addCity($city_name);
            if ($city_id) {
                $response = ['status' => 'success', 'message' => 'City added successfully.', 'city_id' => $city_id];
            } else {
                $response = ['status' => 'error', 'message' => 'Failed to add city.'];
            }
        } else {
            $response = ['status' => 'error', 'message' => 'City name cannot be empty.'];
        }
    } elseif ($action == 'edit_city') {
        $city_id = intval($_POST['city_id']);
        $city_name = $_POST['city_name'];
        if (!empty($city_name)) {
            if (editCity($city_id, $city_name)) {
                $response = ['status' => 'success', 'message' => 'City updated successfully.'];
            } else {
                $response = ['status' => 'error', 'message' => 'Failed to update city.'];
            }
        } else {
            $response = ['status' => 'error', 'message' => 'City name cannot be empty.'];
        }
    } elseif ($action == 'delete_city') {
        $city_id = intval($_POST['city_id']);
        if (deleteCity($city_id)) {
            $response = ['status' => 'success', 'message' => 'City deleted successfully.'];
        } else {
            $response = ['status' => 'error', 'message' => 'Failed to delete city.'];
        }
    }

    echo json_encode($response);
    exit();
}

function renderAdminLogin($error) {
    return '
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Admin Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Bootstrap 5 CSS -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
        <!-- Font Awesome -->
        <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" rel="stylesheet">
        <style>
            body {
                background-color: #f8f9fa;
            }
        </style>
    </head>
    <body>
    <div class="container d-flex align-items-center justify-content-center min-vh-100">
        <div class="card shadow-sm w-100" style="max-width: 420px;">
            <div class="card-body">
                <h3 class="card-title text-center mb-4">Admin Login</h3>
                '.(!empty($error) ? "<div class='alert alert-danger'>{$error}</div>" : '').'
                <form method="POST">
                    <div class="mb-3">
                        <label for="username" class="form-label">Username</label>
                        <input type="text" class="form-control" id="username" name="username" required autofocus>
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">Password</label>
                        <input type="password" class="form-control" id="password" name="password" required>
                    </div>
                    <button type="submit" class="btn btn-primary w-100">Login</button>
                </form>
            </div>
        </div>
    </div>
    </body>
    </html>';
}

// Fetch data to display
$users = getUsers();
$cities = getCities();

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Admin Dashboard</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .navbar-brand {
            font-weight: bold;
        }
        .card {
            margin-top: 20px;
        }
        .modal .modal-header {
            border-bottom: none;
        }
        .modal .modal-footer {
            border-top: none;
        }
        /* Additional custom styles */
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
    <div class="container">
        <a class="navbar-brand" href="#">Admin Dashboard</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
       </button>
       <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="?logout" onclick="return confirm('Are you sure you want to log out?');">Logout</a>
                </li>
            </ul>
       </div>
    </div>
</nav>

<div class="container mt-4">
    <div id="message" class="alert" style="display: none;"></div>

    <!-- Manage Users -->
    <div class="card">
        <div class="card-header">
            <h3>Manage Users</h3>
        </div>
        <div class="card-body">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>Username</th>
                        <th>City</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody id="users-table">
                <?php foreach ($users as $user) : ?>
                    <tr>
                        <td><?php echo htmlspecialchars($user['username']); ?></td>
                        <td><?php echo htmlspecialchars($user['city_name']); ?></td>
                        <td>
                            <span class="badge bg-<?php echo $user['approved'] ? 'success' : 'warning'; ?>">
                                <?php echo $user['approved'] ? 'Approved' : 'Pending'; ?>
                            </span>
                        </td>
                        <td>
                            <?php if (!$user['approved']): ?>
                                <button class="btn btn-success btn-sm me-1" onclick="approveUser(<?php echo $user['id']; ?>)">
                                    <i class="fas fa-check"></i> Approve
                                </button>
                            <?php endif; ?>
                            <button class="btn btn-danger btn-sm" onclick="deleteUser(<?php echo $user['id']; ?>)">
                                <i class="fas fa-trash"></i> Delete
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Manage Cities -->
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h3>Manage Cities</h3>
            <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addCityModal">
                <i class="fas fa-plus"></i> Add City
            </button>
        </div>
        <div class="card-body">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>City Name</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody id="cities-table">
                <?php foreach ($cities as $city) : ?>
                    <tr>
                        <td><?php echo htmlspecialchars($city['name']); ?></td>
                        <td>
                            <button class="btn btn-warning btn-sm me-1" data-bs-toggle="modal" data-bs-target="#editCityModal"
                                    data-id="<?php echo $city['id']; ?>" data-name="<?php echo htmlspecialchars($city['name']); ?>">
                                <i class="fas fa-edit"></i> Edit
                            </button>
                            <button class="btn btn-danger btn-sm" onclick="deleteCity(<?php echo $city['id']; ?>)">
                                <i class="fas fa-trash"></i> Delete
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- Add City Modal -->
<div class="modal fade" id="addCityModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="add-city-form">
                <div class="modal-header">
                    <h5 class="modal-title">Add New City</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="city_name" class="form-label">City Name</label>
                        <input type="text" class="form-control" id="city_name" name="city_name" required>
                    </div>
                    <!-- Include other fields if necessary -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="addCity()">Add City</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Edit City Modal -->
<div class="modal fade" id="editCityModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form id="edit-city-form">
                <div class="modal-header">
                    <h5 class="modal-title">Edit City</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="editCityName" class="form-label">City Name</label>
                        <input type="text" class="form-control" id="editCityName" name="city_name" required>
                        <input type="hidden" id="editCityId" name="city_id">
                    </div>
                    <!-- Include other fields if necessary -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="saveCityChanges()">Save Changes</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Bootstrap 5 JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<!-- jQuery (for AJAX calls) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
// JavaScript and jQuery code

function displayMessage(type, message) {
    const msgDiv = $('#message');
    msgDiv.removeClass('alert-success alert-danger').addClass('alert-' + type).text(message).slideDown();
    setTimeout(() => msgDiv.slideUp(), 3000);
}

function updateContent() {
    // Get updated users and cities via AJAX
    $.get('dashboard_admin.php', function(data) {
        const newUsers = $(data).find('#users-table').html();
        const newCities = $(data).find('#cities-table').html();
        $('#users-table').html(newUsers);
        $('#cities-table').html(newCities);
    });
}

function approveUser(userId) {
    if (confirm('Are you sure you want to approve this user?')) {
        $.post('dashboard_admin.php', { action: 'approve_user', user_id: userId }, function(response) {
            displayMessage(response.status === 'success' ? 'success' : 'danger', response.message);
            updateContent();
        }, 'json');
    }
}

function deleteUser(userId) {
    if (confirm('Are you sure you want to delete this user?')) {
        $.post('dashboard_admin.php', { action: 'delete_user', user_id: userId }, function(response) {
            displayMessage(response.status === 'success' ? 'success' : 'danger', response.message);
            updateContent();
        }, 'json');
    }
}

function addCity() {
    const cityName = $('#city_name').val().trim();
    if (cityName === '') {
        alert('City name cannot be empty.');
        return;
    }
    $.post('dashboard_admin.php', { action: 'add_city', city_name: cityName }, function(response) {
        displayMessage(response.status === 'success' ? 'success' : 'danger', response.message);
        if (response.status === 'success') {
            $('#addCityModal').modal('hide');
            $('#add-city-form')[0].reset();
            updateContent();
        }
    }, 'json');
}

function saveCityChanges() {
    const cityId = $('#editCityId').val();
    const cityName = $('#editCityName').val().trim();
    if (cityName === '') {
        alert('City name cannot be empty.');
        return;
    }
    $.post('dashboard_admin.php', { action: 'edit_city', city_id: cityId, city_name: cityName }, function(response) {
        displayMessage(response.status === 'success' ? 'success' : 'danger', response.message);
        if (response.status === 'success') {
            $('#editCityModal').modal('hide');
            updateContent();
        }
    }, 'json');
}

function deleteCity(cityId) {
    if (confirm('Are you sure you want to delete this city?')) {
        $.post('dashboard_admin.php', { action: 'delete_city', city_id: cityId }, function(response) {
            displayMessage(response.status === 'success' ? 'success' : 'danger', response.message);
            updateContent();
        }, 'json');
    }
}

// Event listener for opening the Edit City modal
$('#editCityModal').on('show.bs.modal', function(event) {
    const button = $(event.relatedTarget);
    const cityId = button.data('id');
    const cityName = button.data('name');
    $('#editCityId').val(cityId);
    $('#editCityName').val(cityName);
});

</script>
</body>
</html>

functions:

<?php
// functions.php

// Database configuration - update with your actual database credentials
$servername = "localhost";
$username = "root"; // Replace with your actual DB username
$password = "";     // Replace with your actual DB password
$dbname = "city_inventory_app";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Set character set to UTF-8
$conn->set_charset('utf8mb4');

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to sanitize input
function sanitize($data) {
    global $conn;
    return $conn->real_escape_string(htmlspecialchars(strip_tags(trim($data))));
}

// Function to get list of cities
function getCities() {
    global $conn;
    $stmt = $conn->prepare("SELECT * FROM cities ORDER BY name ASC");
    $stmt->execute();
    return $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
}

// Function for admin login
function adminLogin($username, $password) {
    global $conn;
    $username = sanitize($username);
    $stmt = $conn->prepare("SELECT * FROM admin_users WHERE username = ? LIMIT 1");
    $stmt->bind_param("s", $username);
    $stmt->execute();

    $admin = $stmt->get_result()->fetch_assoc();

    if ($admin && password_verify($password, $admin['password'])) {
        return true;
    } else {
        return false;
    }
}

// Function for user login
function loginUser($username, $password, $city_id) {
    global $conn;
    $username = sanitize($username);
    $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND city_id = ? LIMIT 1");
    $stmt->bind_param("si", $username, $city_id);
    $stmt->execute();

    $user = $stmt->get_result()->fetch_assoc();

    if ($user && password_verify($password, $user['password'])) {
        // Check if user is approved
        if ($user['approved']) {
            $_SESSION['user_logged_in'] = true;
            $_SESSION['user_id'] = $user['id'];
            $_SESSION['username'] = $user['username'];
            $_SESSION['city_id'] = $user['city_id'];
            return true;
        } else {
            return "Your account is not approved yet.";
        }
    } else {
        return "Invalid login credentials.";
    }
}

// Function to get user city_id
function getUserCityId($user_id) {
    global $conn;
    $stmt = $conn->prepare("SELECT city_id FROM users WHERE id = ?");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();

    $result = $stmt->get_result()->fetch_assoc();
    return $result['city_id'];
}

// Function to get items by city
function getItemsByCity($city_id) {
    global $conn;
    $stmt = $conn->prepare("SELECT * FROM items WHERE city_id = ?");
    $stmt->bind_param("i", $city_id);
    $stmt->execute();
    return $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
}

// Function to add item
function addItem($name, $city_id, $current, $prev1, $prev2) {
    global $conn;
    $name = sanitize($name);
    $stmt = $conn->prepare("INSERT INTO items (name, city_id, current_year_quantity, prev_year_1_quantity, prev_year_2_quantity) VALUES (?, ?, ?, ?, ?)");
    $stmt->bind_param("siiii", $name, $city_id, $current, $prev1, $prev2);
    return $stmt->execute();
}

// Function to fetch users for admin dashboard
function getUsers() {
    global $conn;
    $stmt = $conn->prepare("SELECT users.id, users.username, users.approved, cities.name AS city_name FROM users LEFT JOIN cities ON users.city_id = cities.id");
    $stmt->execute();
    return $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
}

// Function to approve user
function approveUser($user_id) {
    global $conn;
    $stmt = $conn->prepare("UPDATE users SET approved = 1 WHERE id = ?");
    $stmt->bind_param("i", $user_id);
    return $stmt->execute();
}

// Function to delete user
function deleteUser($user_id) {
    global $conn;
    $stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
    $stmt->bind_param("i", $user_id);
    return $stmt->execute();
}

// Function to add a city
function addCity($city_name) {
    global $conn;
    $city_name = sanitize($city_name);
    $stmt = $conn->prepare("INSERT INTO cities (name) VALUES (?)");
    $stmt->bind_param("s", $city_name);
    if ($stmt->execute()) {
        return $conn->insert_id;
    }
    return false;
}

// Function to edit a city
function editCity($city_id, $city_name) {
    global $conn;
    $city_name = sanitize($city_name);
    $stmt = $conn->prepare("UPDATE cities SET name = ? WHERE id = ?");
    $stmt->bind_param("si", $city_name, $city_id);
    return $stmt->execute();
}

// Function to delete a city
function deleteCity($city_id) {
    global $conn;
    $stmt = $conn->prepare("DELETE FROM cities WHERE id = ?");
    $stmt->bind_param("i", $city_id);
    return $stmt->execute();
}
?>