<?php
include "dp.php";

$nationality  = $_POST['nationality'];
$name ='/^[-a-zA-Z_\p{Arabic}-\s]*$/u';

if (empty($nationality)){
  echo "
        <div class='alert alert-warning'>
        <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;' >&times;</a>
        <b>سجل الجنسية </b>
        </div>
  ";
  exit();
}else{
if(!preg_match($name,$nationality)){
  echo "
  <div class='alert alert-warning'>
  <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
  <b> تأكد  من حروف الجنسية  ... يوجد خطأ في  </b>
  <b>$nationality</b>
  </div>
  ";
  exit();
}

// existing nation name  your database

$sql = "SELECT nation_id , nationality FROM nations WHERE nationality = '$nationality' LIMIT 1";
$check_query = mysqli_query($con,$sql);
$count_nation = mysqli_num_rows($check_query);
if($count_nation > 0){
  echo "
  <div class='alert alert-danger'>
  <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
  <b>تم تسجيل هذه الجنسية من قبل  ... اكمل  بجنسية أخري</b>
  </div>
  ";
  exit();
}else {
      $sql =" INSERT INTO nations(nation_id, nationality)
              VALUES (NULL, '$nationality')";
        $run_query = mysqli_query($con,$sql);
              if($run_query){
          echo "
          <div class='alert alert-success'>
          <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
          <b>تم تسجيل بياناتك بنجاح ..... !</b>
          </div>
          ";}
        else{ echo ("<div class='alert alert-danger'>
        <a href='#' class='close' data-dismiss='alert' aria-label='close'style='float:left;'>&times;</a>
        <b>يومك جاز لم يتم تسجيل اي شيء</b>
        </div>
        ".mysqli_connect_error());}
      }
    }

?>
