<?php
session_start();
require_once("config/configDB.php"); 
require "userPermission.php";
function validation_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

 $suppliername   = stripslashes($_POST['suppliername']);
 $sname_tamil   = stripslashes($_POST['sname_tamil']);
 
    $address1       = stripslashes($_POST['address1']);
   $suppliercode   = stripslashes($_POST['suppliercode']);
    $area          = stripslashes($_POST['area']);
	 $area_tamil          = stripslashes($_POST['area_tamil']);
   
    $pincode        = stripslashes($_POST['pincode']);
    $mobile         = stripslashes($_POST['mobile']);
   
    $createdate  	= date("Y-m-d");
    $createdby      = stripslashes($_POST['createdby']);
    $userID         = stripslashes($_POST['userID']);

$autoinc=mysqli_query($conn,"ALTER TABLE supplier_master CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");

$count=0;
$check_query	= mysqli_query($conn,"SELECT count(cname) as counts FROM supplier_master WHERE sname = '$suppliername' "); // Check the database


while($row = mysqli_fetch_array($check_query)){
$count=$row['counts'];
}
if($count!=0){
// Already Exsist


		echo "<script> alert ('Data Inserted Success.');</script>";
		?>
<script language="javascript">window.location.href = "supplierMasterDashboard.php";</script>
<?php
		

}		
else
{

$sql  = "INSERT INTO supplier_master (sname,sname_tamil, saddress,  area,area_tamil, pincode, mobile, scode, isdelete,createdby,userID,createdate) VALUES ('$suppliername','$sname_tamil', '$address1',  '$area','$area_tamil',  '$pincode', '$mobile',  '$suppliercode', '1','".$createdby."','".$userID."','".$createdate."')";

mysqli_query($conn,$sql);



$conn->close();
}
// productID, customerID, productcode, productname, prodct_description, hsn_code, gst, purchase_rate, sale_rate


header("Location:supplierMasterDashboard.php");




?>