<?php session_name('CAKEPHP'); session_start();
$host = "localhost"; //database location
$user = "root"; //database username
$pass = ""; //database password
$db_name = "compaint_crm"; //database name
//database connection
$link = mysql_connect($host, $user, $pass);
$r=mysql_select_db($db_name);
if(!$r)
{
  die('Error'.DB_error_msg($db));
}
//sets encoding to utf8
mysqli_query($link, "SET NAMES utf8");
 
 	    $SQL_client=mysqli_query($link, "SELECT A.productid,A.product_no , A.productname,A.serialno ,A.CompanyId,B.cf_613 as shade_name from xpert_products A ,xpert_productcf B  Where  A.CompanyId='".$_SESSION['ACGCompanyId']."' " );
	 //	$sql="Select * from clientmaster Where id ='".$q."'";
		//$result = DB_query($sql,$db);
		if(!$SQL_client)
		{
		   die("Error".DB_error_msg($db));
		}
	 
		while($myrow=mysqli_fetch_array($SQL_client))
		{
		$link = mysql_connect('localhost', 'root', $pass);
		$r=mysql_select_db('db_mxerp');
		
			 $qCategoryID=mysqli_query($link, "select id from stockmaincategory where  stockmaincategoryid='FG'  ");
	 		$r1=mysqli_fetch_array($qCategoryID);
 			 $CategoryID=$r1['id'];
			  $qSubCategoryID=mysqli_query($link, "select id from stockcategory where  stockmaincategory='FG'  ");
	 		$r2=mysqli_fetch_array($qSubCategoryID);
			 $SubCategoryID=$r2['id'];

 	 	echo   	$sql= "insert into item_master (CategoryID,SubCategoryID,StockID,item_name,serial_no,CompanyId,shade_name) values('".$CategoryID."','".$SubCategoryID."','".$myrow['product_no']."','".$myrow['shade_name']."','".$myrow['serialno']."','".$myrow['CompanyId']."','".$myrow['productname']."') ";
			 $r=mysqli_query($link, $sql );
			 if(!$r)
			 die('error'.DB_error_msg($db));
 
		}
		
?>
