<?php
date_default_timezone_set('Asia/Kolkata');
require_once("config/configDB.php"); 

$productcode   = stripslashes($_POST['productcode']);
$productname   = stripslashes($_POST['productname']);
$product_type   = $_POST['product_type'];
$qty_type   = stripslashes($_POST['qty_type']);
$purchase_rate   = stripslashes($_POST['purchase_rate']);
$gst   = stripslashes($_POST['gst']);
$hsn_code   = stripslashes($_POST['hsn_code']);
$description   = stripslashes($_POST['description']);
$create_date  	        = date("Y-m-d H:i:s"); 
//productcode, productname, purchase_rate, gst, hsn_code,description, create_date, flag FROM `product_master`
$autoinc=mysqli_query($conn,"ALTER TABLE product_master CHANGE id id INT(11) NOT NULL AUTO_INCREMENT ");


$count=0;
$check_query	= mysqli_query($conn,"SELECT count(productcode) as counts FROM product_master WHERE productcode = '$productcode' "); // 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 = "productMasterDashboard.php";</script>
<?php
		

}		
else
{

$sql  = "INSERT INTO product_master (productcode, productname,product_type,qty_type, purchase_rate, gst, hsn_code,prodct_description, create_date, isdelete) VALUES ('$productcode','$productname','$product_type','$qty_type','$purchase_rate','$gst','$hsn_code','$description','$create_date', '1')";



mysqli_query($conn,$sql);

$last_id = mysqli_insert_id($conn);


}
$conn->close();

// productID, customerID, productcode, productname, prodct_description, hsn_code, gst, purchase_rate, sale_rate



header("Location:productMasterDashboard.php");


?>