
<?php
// Include the database configuration file
include("includes/db.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Collect data from the form
    $subjectCode = $conn->real_escape_string($_POST["subjectCode"]);
    $subjectName = $conn->real_escape_string($_POST["subjectName"]);
    $theoryFullMarks = $conn->real_escape_string($_POST["theory_full_marks"]);
    $internalFullMarks = $conn->real_escape_string($_POST["internal_full_marks"]);
    $theoryCreditHour = $conn->real_escape_string($_POST["theory_credit_hour"]);
    $internalCreditHour = $conn->real_escape_string($_POST["internal_credit_hour"]);

    // SQL query to insert data into the 'subjects' table
    $query = "INSERT INTO subjects (subject_code, subject_name,theory_full_marks,internal_full_marks,theory_credit_hour,internal_credit_hour) VALUES ('$subjectCode', '$subjectName','$theoryFullMarks','$internalFullMarks','$theoryCreditHour','$internalCreditHour')";

    if ($conn->query($query) === TRUE) {
        // Subject added successfully
        header("Location: add_subject.php?success=1");
        exit();
    } else {
        // Error occurred while adding subject
        header("Location: add_subject.php?error=1");
        exit();
    }

    // Close the database connection
    $conn->close();
}
?>
