<?php
//require_once('mysql.php');
//	$dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $con=mysqli_connect("localhost","dhdogzbe_sjo","@SDE$#!@SAWcfgh","dhdogzbe_pos");
   $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
  //  $dbb=mysqli_connect("localhost","vosmcyqy_fas","J78RhHUY765@@23@PLasd","vosmcyqy_safe");
    //$dvv=mysqli_connect("localhost","vosmcyqy_af","2@RhUH7JY78@@@9823@KLULasd","vosmcyqy_afri");
//mysql_select_db("point_of_sale", $con);
$b=mysqli_real_escape_string($con,trim($_POST['b']));
//$a=mysql_real_escape_String($_POST['a']);
//$c=mysql_real_escape_String($_POST['c']);
$vat=mysqli_real_escape_string($con,trim($_POST['vat']));
 $l=mysqli_real_escape_string($con,trim($_POST['category']));
$qty=mysqli_real_escape_string($con,trim($_POST['qty']));
$min=mysqli_real_escape_string($con,trim($_POST['mini']));
//$d=$_POST['d'];
$e=mysqli_real_escape_string($con,trim($_POST['e']));
//$p=$_POST['p'];
//$m=$_POST['m'];$k=$_POST['k'];
//$v=$_POST['v'];
//$pac=$_POST['code'];
//$re=$_POST['reorder'];
$price=$_POST['SELLING'];
$r="select * from categories where id='$l'";
$sql=mysqli_query($con,$r);
$row=mysqli_fetch_array($sql);
$category='BELTS';
$number=$row['current'];
$number=$number+1;

$f='0';	

$nm="update categories set current='$number' where name='$category'";
$mn=mysqli_query($con,$nm);	
 
 $ft=mysqli_query($dbc,("select * from products where p_name='$b'"));
       if(mysqli_num_rows($ft)==0){
$sq="INSERT INTO products (p_name,description,sold,left_p,price,category,buying,minimum)
VALUES ('$b','$b','$f','0','$price','$category','$e','$min')";
$fu=mysqli_query($dbc,$sq);
}
$fb=mysqli_query($con,("select * from products where p_name='$b'"));
    if(mysqli_num_rows($fb)==0){
$sql="INSERT INTO products (p_name,description,sold,left_p,price,category,buying,minimum)
VALUES ('$b','$b','$f','$qty','$price','$category','$e','$min')";

   

$nb=mysqli_query($con,$sql);

 }
  $fbb=mysqli_query($dbb,("select * from products where p_name='$b'"));
    if(mysqli_num_rows($fbb)==0){
$sql="INSERT INTO products (p_name,description,sold,left_p,price,category,buying,minimum)
VALUES ('$b','$b','$f','0','$price','$category','$e','$min')";

   

$nb=mysqli_query($dbb,$sql);

  }
    $fcc=mysqli_query($dvv,("select * from products where p_name='$b'"));
    if(mysqli_num_rows($fcc)==0){
$sql="INSERT INTO products (p_name,description,sold,left_p,price,category,buying,minimum)
VALUES ('$b','$b','$f','0','$price','$category','$e','$min')";

   

$nb=mysqli_query($dvv,$sql);

  }
    
 header("location: products_view.php");
		exit();
  

mysqli_close($con);
mysqli_close($dbc);
mysqli_close($dbb);
mysqli_close($dvv);
	
?>