<?php

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

$id = $_POST['id'];

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

$club_name = $_POST['club_name'];
//$districtid=$_POST['district'];




$totalclub = findQuery("select COUNT(*) nos from tbl_club where club_name='$club_name' and status=0 and id!=$id");
$count     = $totalclub[0]['nos'];




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


    $encodedMessage = urlencode($message);



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

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


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

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



    $encodedMessage = urlencode($message);



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

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