<?php

include 'includes/database.php';
include 'includes/functions.php';
$conn= new Functions();
$redirect = $conn->base_url()."clergy";

if(!empty($_POST['name']) && !empty($_POST['designation'])
&& !empty($_POST['id']) && !empty($_POST['church'])) {
    $name = $_POST['name'];
    $designation = $_POST['designation'];
    $church = $_POST['church'];   
    $sex = $_POST['sex'];
    $amount = $_POST['amount'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $district = $_POST['district'];
    $bible = $_POST['bible'];
    $conyear = $_POST['conyear'];
    $id = $_POST['id'];





//process inserting of data into database
        $sql = "UPDATE clergy SET name=:name, designation=:designation, districtID=:district, sex=:sex,
                church=:church, conyear=:conyear, phone=:phone, bible=:bible, amount=:amount, address=:address, id=:id WHERE id =:id";
        $conn->query($sql);
        $conn->bind(":name", $name);
        $conn->bind(":designation", $designation);
        $conn->bind(":district", $district);
        $conn->bind(":sex", $sex);
        $conn->bind(":church", $church);
        $conn->bind(":amount", $amount);
        $conn->bind(":phone", $phone);
        $conn->bind(":address", $address);        
        $conn->bind(":bible", $bible);
        $conn->bind(":conyear", $conyear);
        $conn->bind(":id", $id);


        $send = $conn->execute();
        if ($send) {
            echo "<script>
$(function () { //ready
          toastr.options.progressBar = true, toastr.options.preventDuplicates = true,
          toastr.success('Clergy <b>$name</b> Updated Successfully');
      });
</script><meta http-equiv='refresh' content='5; $redirect'>";
        }else {
            echo "<script>
$(function () { //ready
          toastr.options.progressBar = true, toastr.options.preventDuplicates = true,
          toastr.error('An Error Occurred While Updating Data');
      });
</script> <meta http-equiv='refresh' content='4; $redirect'>";
        }


}else {
    echo "<script>
$(function () { //ready
          toastr.options.progressBar = true, toastr.options.preventDuplicates = true,
          toastr.error('All Marked (*) Are Required');
      });
</script>";
    return false;
}