GIF89a php
Current File : /home/hencockfreshchic/public_html/admin.cpanel/uploads/addProduct.php
<?php
ob_start();
ini_set('error_reporting', E_STRICT);
include("connect.php");
mysqli_set_charset($conn,'utf8');

$cat=str_replace("'","\'",$_POST['cat']);
$subcat=str_replace("'","\'",$_POST['subcat']);


$qty=$_POST['qty'];
$rprice=$_POST['rprice'];
$sprice=$_POST['sprice'];
$pcode=$_POST['pcode'];
$mff=str_replace("'","\'",$_POST['mff']);

$s_charge=$_POST['s_charge'];
$prod_cod=$_POST['prod_cod'];
$pname=str_replace("'","\'",$_POST['pname']);
$desc=str_replace("'","\'",$_POST['desc']);
$uid=rand(10004545,100000);
$user_id=$_COOKIE["user_idd"];
$user_type=$_COOKIE["user_typee"];

$colors=$_POST['colors'];
$sizes=$_POST['sizes'];
$gst=$_POST['gst'];

// check banner is avail or not


// target directory
$target_dir='prod_image/'.mt_rand(100,987).mt_rand(985,1453).trim($_FILES["image"]["name"]);


if($_FILES["image"]["name"]=="")
{

		//runQuery($cat,$subcat,$pname,$qty,$rprice,$sprice,$pcode,$mff,$desc,$url);
		if($user_type=='1' || $user_type=='2'){
			$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','NA','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','1','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
		}
		else
		{
			$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','NA','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','0','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
		}
			

$rs=mysqli_query($conn,$sql);

if($rs>0)
{
	 echo '<script>alert("Product saved successfully");</script>';
     echo '<script>window.location.href="addremoveproduct.php";</script>';
	// header("Location: cardMe.php?uid=".$uid."");
}
else
{
		 echo '<script>alert("Unable to save products");</script>';
		echo '<script>window.location.href="addremoveproduct.php";</script>';
}

}
else
{

/*// Check if file already exists
if (file_exists($target_dir)) {
   echo '<script>alert("Image already exist | try another file");</script>';
   echo '<script>window.location.href="addremoveproduct.php";</script>';
}
else
{*/
	$FileType = strtolower(pathinfo($target_dir,PATHINFO_EXTENSION));
	if($FileType != "png" && $FileType != "jpg" && $FileType != "jpeg" )
{
	// file format not supportedonly images allows
	 echo '<script>alert("Invalid image format");</script>';
 	echo '<script>window.location.href="addremoveproduct.php";</script>';
	
}
else
{


// check banner is avil or not
if($cat=="Banner2" && $subcat=="Banner2"){
	$sql1="SELECT * FROM `products` WHERE `cat_name`='".$cat_name."' && `subcat_name`='".$subcat."'";
	$rs1=mysqli_query($conn,$sql1);
	$check1=mysqli_num_rows($rs1);
	if($check1>0){
			 echo '<script>alert("Banner image already available");</script>';
     echo '<script>window.location.href="addremoveproduct.php";</script>';

	}
	else
	{
		move_uploaded_file($_FILES["image"]["tmp_name"],$target_dir);
		//runQuery($cat,$subcat,$pname,$qty,$rprice,$sprice,$pcode,$mff,$desc,$url);
		if($user_type=='1' || $user_type=='2'){
			$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','".$target_dir."','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','1','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
		}
		else
		{
			$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','".$target_dir."','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','0','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
		}
			

$rs=mysqli_query($conn,$sql);

if($rs>0)
{
	 echo '<script>alert("Product saved successfully");</script>';
     echo '<script>window.location.href="addremoveproduct.php";</script>';
	// header("Location: cardMe.php?uid=".$uid."");
}
else
{
		 echo '<script>alert("Unable to save products");</script>';
		echo '<script>window.location.href="addremoveproduct.php";</script>';
}
	}
}else{	
	//runQuery($cat,$subcat,$pname,$qty,$rprice,$sprice,$pcode,$mff,$desc,$url);


move_uploaded_file($_FILES["image"]["tmp_name"],$target_dir);
if($user_type=='1' || $user_type=='2'){
		$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','".$target_dir."','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','1','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
	} else {
		$sql="INSERT INTO `products`(`cat_name`, `subcat_name`, `p_name`, `qty`, `real_price`, `sale_price`, `p_code`, `manufacturer`, `p_desc`, `image`, `datee`,`ship_chrg`,`cod`,`prod_approval`,`user_id`,`user_type`,`priority`,`p_color`, `p_size`,`gst`) VALUES ('".$cat."','".$subcat."','".$pname."','".$qty."','".$rprice."','".$sprice."','".$pcode."','".$mff."','".$desc."','".$target_dir."','".date('Y-m-d')."','".$s_charge."','".$prod_cod."','0','".$user_id."','".$user_type."','0','".$colors."','".$sizes."','".$gst."')";
	}
		

$rs=mysqli_query($conn,$sql);

if($rs>0)
{
	 echo '<script>alert("Product saved successfully");</script>';
     echo '<script>window.location.href="addremoveproduct.php";</script>';
	// header("Location: cardMe.php?uid=".$uid."");
}
else
{
		 echo '<script>alert("Unable to save products");</script>';
	echo '<script>window.location.href="addremoveproduct.php";</script>';
}
}
}
}


function runQuery($cat,$subcat,$pname,$qty,$rprice,$sprice,$pcode,$mff,$desc,$url){

}
?>