<head>
<script src="dist/sweetalert-dev.js"></script>
<link rel="stylesheet" href="dist/sweetalert.css">
</head>
<?php
if($_POST['submit']){
 include("db.php");
    
    $customerName=$_POST['customerName'];
    $fname=$_POST['fname']; 
    $phone=$_POST['phone'];
    $address=$_POST['address'];
    $desc=$_POST['desc'];
   
   echo "<br>";
  //کنترل کردن برای جلوگیری از دوبار وارد کردن
  $coCustomerSql="select * from customers where name='$customerName' and remove='0'  ";
  $coCustomerQuery=$db ->query($coCustomerSql);
  $coCustomerRow=$coCustomerQuery ->fetch_array();
  $coCustomer=$coCustomerRow['name'];
  $id=$coCustomerRow['id'];
  if(isset($coCustomer)){
  
   
          echo' <script>
					sweetAlert("اخطار...", "اطلاعات وارده در سیستم موجود است", "error");
			   </script>'; 
			   echo '<meta http-equiv="refresh" content ="1; url=add_customer.php" >';
			   // header("location: add_customer.php");
			 die;
			 
  
  
  }
   
  //================================================================================
      echo $insertionSql="insert into customers (name,fname,phone,address,description) values
	  ('$customerName','$fname','$phone','$address','$desc')";
      
	   
	  $insertionQuery= $db ->query($insertionSql);
	  if($insertionQuery){
	  		 echo' <script>
					 
					
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
				</script>';
	   echo '<meta http-equiv="refresh" content ="1; url=add_customer.php" >';
	    
	  }

}

?>