<?php
include_once"../config.php";
include_once"function.php";
session_start();
$q = mysqli_query($con, "select value from uae where id = 1");
$r = mysqli_fetch_object($q);
$uaevalue = $r->value;
$per = $_POST['per'];
$value = ($uaevalue*$per) / 100;
$name = $_POST['name'];
$status = $_POST['status'];
$id = isset($_POST['id'])?$_POST['id']:null;

$submit = isset($_POST['submit'])?$_POST['submit']:null;
$update = isset($_POST['update'])?$_POST['update']:null;
$delete = isset($_GET['delete'])?$_GET['delete']:null;

if($submit){
	
	
mysqli_query($con, "INSERT INTO emirate set name= '$name', percent= '$per', value = '$value', status = '$status'  ");
$_SESSION['try']=1;
header("location:../emirates.php?try=1");

}else if($update && $id){
	mysqli_query($con, "update emirate set name= '$name', percent= '$per', value = '$value', status = '$status' where id =  $id ");
	emirate_area($id, $value, $con);
    emirate_nationailty($id,$value,$con);
	emirate_category($id,$value,$con);
$_SESSION['try']=2;
header("location:../emirates.php?try=2");

}elseif($delete){
	mysqli_query($con, "delete from emirate where id =  $delete ");
   $_SESSION['try']=3;
   header("location:../emirates.php?try=3");
}

