<?php




require('../lib/dbclass.php');

$id = $_POST['id'];

if (!$id) {
    $id = 0;
}

$panchayat_name = $_POST['panchayat_name'];
$assembly_id    = $_POST['assembly_id'];




$totalassembly = findQuery("select COUNT(*) nos from tbl_panchayat where panchayat_name='$panchayat_name' and assembly_id=$assembly_id and status=0 and id!=$id");
$count         = $totalassembly[0]['nos'];




if ($count > 0) {
    $message = 'Already Taken.';


    $encodedMessage = urlencode($message);



    $url = "add_panchayat.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
} else {
    unset($_POST['id']);


    $id = saveArray('tbl_panchayat', $_POST, $id);
}

if ($id) {
    $message = 'Registered successfully!';



    $encodedMessage = urlencode($message);



    $url = "add_panchayat.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
} else {
    $message = 'Something went wrong, please try again.';


    $encodedMessage = urlencode($message);



    $url = "add_panchayat.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
}
