<?php




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

$id = $_POST['id'];

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

$name       = $_POST['name'];
$districtid = $_POST['district'];




$totalassembly = findQuery("select COUNT(*) nos from tbl_assembly where name='$name' and district=$districtid and status=0 and id!=$id");
$count         = $totalassembly[0]['nos'];




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


    $encodedMessage = urlencode($message);



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

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


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

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



    $encodedMessage = urlencode($message);



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

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