<?php
include('connection.php');

if (!isset($_POST['submit'])) {
    // Invalid request method
    header("Location: add_credit.php?error=Invalid request method.");
    exit();
}

$userId = mysqli_real_escape_string($conn, $_POST['user_id']);
$user_type = mysqli_real_escape_string($conn, $_POST['user_type']);
$credit = mysqli_real_escape_string($conn, $_POST['credit']);
 $credit_note = mysqli_real_escape_string($conn, $_POST['credit_note']);
$currentDateTime = date('Y-m-d H:i:s');
$added_by = "Admin";
$credit_type = "Add Credit";

$sql = "INSERT INTO credit (added_by, user_type, user_id, credit, credit_type, credit_note, date_time) VALUES ('$added_by','$user_type','$userId','$credit','$credit_type','$credit_note','$currentDateTime')";
$result = mysqli_query($conn, $sql);

if ($result) {
    $successMessage = "Credit Added Successfully!";
    header("Location: add_credit.php?success=" . $successMessage);
} else {
    $errorMessage = "Failed insertion!";
    header("Location: add_credit.php?error=" . $errorMessage);
}
exit();
?>

<!-- Add this JavaScript code to display SweetAlert messages -->

