<?php

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

$id = $_POST['id'];

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



$panchayat_id = $_POST['panchayat_id'];
$ward_name    = $_POST['ward_name'];


$totalward = findQuery("select COUNT(*) nos from tbl_ward where ward_name='$ward_name' and panchayat_id=$panchayat_id and status=0 and id!=$id");
$count     = $totalward[0]['nos'];




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


    $encodedMessage = urlencode($message);



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

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


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

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



    $encodedMessage = urlencode($message);



    $url = "add_ward.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_ward.php?message={$encodedMessage}";

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