<?php session_start();
if(empty($_SESSION['id'])):
header('Location:../index.php');
endif;

include('../dist/includes/dbcon.php');
	$id = $_POST['id'];
	$desc = $_POST['desc'];
	$name =$_POST['prod_name'];
	$branchko =$_POST['branchko'];
	$price1 = $_POST['prod_price1'];
	$price2 = $_POST['prod_price2'];
	$price3 = $_POST['prod_price3'];
	$cm = $_POST['cm'];
	$cmm = $_POST['cmm'];
	$serial = $_POST['serial'];
	$pic = $_FILES["image"]["name"];
			if ($pic=="")
			{	
				if ($_POST['image1']<>""){
					$pic=$_POST['image1'];
				}
				else
					$pic="default.gif";
			}
			else
			{
				$pic = $_FILES["image"]["name"];
				$type = $_FILES["image"]["type"];
				$size = $_FILES["image"]["size"];
				$temp = $_FILES["image"]["tmp_name"];
				$error = $_FILES["image"]["error"];
			
				if ($error > 0){
					die("Error uploading file! Code $error.");
					}
				else{
					if($size > 100000000000) //conditions for the file
						{
						die("Format is not allowed or file size is too big!");
						}
				else
				      {
					move_uploaded_file($temp, "../dist/uploads/".$pic);
				      }
					}
			
			}
			
	mysqli_query($con,"update product set prod_name='$name',prod_price='$price1',prod_price2='$price2',prod_price3='$price3',branch_id='$branchko',prod_pic='$pic',serial='$serial',prod_desc='$desc',cm='$cm',cmm='$cmm' where prod_id='$id'")or die(mysqli_error($con));
	
	echo "<script type='text/javascript'>alert('Successfully updated product details!');</script>";
	echo "<script>document.location='product.php'</script>";  

	
?>
