<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

$maindb = 'item';
$myyear = $_SESSION[$myyear];
$maindb3 = 'apps4rea_msp_3_' . $myyear;
$maindb1 = 'apps4rea_msp_1_' . $myyear;
$maindb2 = 'apps4rea_msp_2_' . $myyear;




$result = mysqli_query($conn, "SELECT * FROM `$maindb3`.$maindb WHERE `code`>= 481 and code <= 495") or die(mysqli_error($conn));

$getnum = mysqli_num_rows($result);
browse($getnum);
while($get = mysqli_fetch_array($result)){
    $code = $get["code"];
    $name = $get["name"];
    $unit = $get["unit"];
    $prodtype = $get["prodtype"];
    $itemgrp = $get["itemgrp"];
    $itemsubgrp = $get["itemsubgrp"];
    $cost = $get["cost"];
    $rate = $get["rate"];
    $msp = $get["msp"];
    $mrp = $get["mrp"];
    $opening = $get["opening"];
    $nmlabels = $get["nmlabels"];
    $hsncode = $get["hsncode"];
    $gstperc = $get["gstperc"];
browse($code);    
mysqli_query($conn, "INSERT INTO `$maindb1`.$maindb(`code`,  `name`, `unit`, `itemgrp`, `itemsubgrp`, `prodtype`,  `cost`, `rate`,`msp`,`mrp`,`opening`,
                                               `nmlabels`, `hsncode`,`gstperc`)
                                        VALUES($code, '$name', '$unit', '$itemgrp','$itemsubgrp', '$prodtype', '$cost', '$rate', '$msp','$mrp','$opening',
                                               '$nmlabels','$hsncode','$gstperc')") or die(mysqli_error($conn));
browse("1");    
mysqli_query($conn, "INSERT INTO `$maindb2`.$maindb(`code`,  `name`, `unit`, `itemgrp`, `itemsubgrp`, `prodtype`,  `cost`, `rate`,`msp`,`mrp`,`opening`,
                                               `nmlabels`, `hsncode`,`gstperc`)
                                        VALUES($code, '$name', '$unit', '$itemgrp','$itemsubgrp', '$prodtype', '$cost', '$rate', '$msp','$mrp','$opening',
                                               '$nmlabels','$hsncode','$gstperc')") or die(mysqli_error($conn));
browse("2");
}

?>
