<?php session_start();
require_once("../config/config.php");
//require_once("../config/commonsetting.php");
$myformId=SESS_MASTER;
$myIp= ipCheck() ;
$dateceated=date("Y-m-d G:i:s");
$createdby='0';
$user_id=$_SESSION[ADD_TAG.'_UserId_vendor'];
// $olga="DELETE FROM product_master WHERE created_by='$user_id' AND created_type='vendor'"; 
// $stmts = $conn->prepare($olga);
// $stmts->execute();
$handle = fopen($_FILES[SESS_MASTER.'upload_data']['tmp_name'], "r");
$headers = fgetcsv($handle, 1000, ",");
$data = fgetcsv($handle, 1000, ",");
$num = count($data);
if($num<=250){
while (($data = fgetcsv($handle, 1000, ","))!== FALSE) 
{
try{
$company_name=addslashes($data[0]);
$short_title=addslashes($data[1]);
$full_title=addslashes($data[2]);
$link=addslashes($data[3]);
$product_image=addslashes($data[4]);
$category=addslashes($data[5]);
$exp_date=addslashes($data[6]);
$from_site=addslashes($data[7]);
$coupon_country_name=addslashes($data[8]);
$amount=addslashes($data[9]);
$brand_store=addslashes($data[10]);
if($company_name!='' && $short_title!='' && $full_title!=''&& $link!='' && $category!='' && $exp_date!='' && $coupon_country_name!=''){
$olgaquery="INSERT INTO product_master SET company_name='$company_name', title ='$short_title', discription='$full_title',product_url='$link',product_image='$product_image',category='$category',exp_date='$exp_date',country_name='$coupon_country_name',brand_store='$brand_store'
,trending='$trending',created_by='$user_id',created_type='vendor',amount='$amount'"; 
$stmt = $conn->prepare($olgaquery);
if($stmt->execute()){
$last_insert_id = $conn->lastInsertId();
$status='success';
$_SESSION["uploaded"] = $status ;
header("location:../merchant-tab-product/".$user_id);
}
}else{
$olga="DELETE FROM product_master WHERE created_by='$user_id' AND created_type='vendor'"; 
$stmts = $conn->prepare($olga);
$stmts->execute();
$status='failed';
unset($_SESSION["uploaded"]);
$_SESSION["uploaded"] = $status ;
break;
header("location:../merchant-tab-product/".$user_id);
}
}
// show error
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
}
echo '<br>';
}else{
$status='failed';
}
$_SESSION["uploaded"] = $status ;
header("location:../merchant-tab-product/".$user_id);
fclose($handle);