<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);


if (isset($_REQUEST['code'])) {

    $code = mysqli_real_escape_string($conn, $_REQUEST['code']);
    $name = mysqli_real_escape_string($conn, $_REQUEST['name']);


    $result = mysqli_query($conn, "SELECT visatype FROM `visamain` WHERE `visatype`= '$name'") or die(mysqli_error($conn));
    $getnum = mysqli_num_rows($result);

    if ($getnum > 0) {
        echo "Cannot Delete Entries Exist For This Visatype.";
    } else {
        if (mysqli_query($conn, "Delete From `visatype` Where `code` = '$code'")) {
            $gdata = mysqli_query($conn, "SELECT name FROM `visatype` order by name")or die(mysqli_error($conn));
            while ($data = mysqli_fetch_array($gdata)) {
                Echo "<option value='$data[name]'>$data[name]</option>";
            }
        }
    }
}
?>
