<?php
// Include your database connection file
include('db_connection.php');
include 'header.php';
if(isset($_GET['id'])) {
    $student_id = $_GET['id'];

    // Fetch student fee data
    $query = "SELECT fees_paid, fees_outstanding FROM students WHERE student_id = $student_id";
    $result = mysqli_query($conn, $query);
    $student = mysqli_fetch_assoc($result);

    if(isset($_POST['update'])) {
        $fees_paid = $_POST['fees_paid'];
        $fees_outstanding = $_POST['fees_outstanding'];

        // Update student fee record
        $update_query = "UPDATE students SET fees_paid='$fees_paid', fees_outstanding='$fees_outstanding' WHERE student_id = $student_id";
        mysqli_query($conn, $update_query);
        
        // Redirect to manage fees page
        header('Location: manage_fees.php');
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit Student Fees</title>
    <link rel="stylesheet" href="form_styles.css">
</head>
<body>
    <form action="" method="post">
        <h2>Edit Student Fees</h2>
        
        <div class="form-group">
            <label for="fees_paid">Fees Paid:</label>
            <input type="text" id="fees_paid" name="fees_paid" value="<?php echo $student['fees_paid']; ?>" required>
        </div>

        <div class="form-group">
            <label for="fees_outstanding">Fees Outstanding:</label>
            <input type="text" id="fees_outstanding" name="fees_outstanding" value="<?php echo $student['fees_outstanding']; ?>" required>
        </div>

        <button type="submit" name="update">Update Fees</button>
    </form>
</body>
</html>
