<?php
include("connection.php");
$productkey=$_POST['productkey'];
$categorykey=$_POST['categorykey'];
$subcategorykey=$_POST['subcategorykey'];
$subsubcategorykey=$_POST['subsubcategorykey'];
$productname=$_POST['productname'];
$description=$_POST['description'];
$filename1=$_FILES['pic1']['name'];
$filepath1=$_FILES['pic1']['tmp_name'];


$filename2=$_FILES['pic2']['name'];
$filepath2=$_FILES['pic2']['tmp_name'];


$filename3=$_FILES['pic3']['name'];
$filepath3=$_FILES['pic3']['tmp_name'];


$description=$_POST['description'];
move_uploaded_file($_FILES['pic1']['tmp_name'],"item1/". $_FILES['pic1']['name']);
move_uploaded_file($_FILES['pic2']['tmp_name'],"item2/". $_FILES['pic2']['name']);
move_uploaded_file($_FILES['pic3']['tmp_name'],"item3/". $_FILES['pic3']['name']);

          if($filename1!='' and $filename2=='' and $filename3=='')
{
move_uploaded_file($_FILES['pic1']['tmp_name'],"item1/". $_FILES['pic1']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',pic1='".$filename1."',description='".$description."'  where productkey=".$productkey;

}

elseif($filename1!='' and $filename2!='' and $filename3=='')
{
move_uploaded_file($_FILES['pic1']['tmp_name'],"item1/". $_FILES['pic1']['name']);
move_uploaded_file($_FILES['pic2']['tmp_name'],"item2/". $_FILES['pic2']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."', pic1='".$filename1."',pic2='".$filename2."',description='".$description."' where productkey=".$productkey;
}

elseif($filename1!='' and $filename2!='' and $filename3!='')
{
move_uploaded_file($_FILES['pic1']['tmp_name'],"item1/". $_FILES['pic1']['name']);
move_uploaded_file($_FILES['pic2']['tmp_name'],"item2/". $_FILES['pic2']['name']);
move_uploaded_file($_FILES['pic3']['tmp_name'],"item3/". $_FILES['pic3']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',pic1='".$filename1."',pic2='".$filename2."', pic3='".$filename3."',description='".$description."' where productkey=".$productkey;
}

elseif($filename1=='' and $filename2=='' and $filename3!='')
{
move_uploaded_file($_FILES['pic3']['tmp_name'],"item3/". $_FILES['pic3']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',pic3='".$filename3."',description='".$description."' where productkey=".$productkey;
}
elseif($filename1=='' and $filename2!='' and $filename3!='')
{
move_uploaded_file($_FILES['pic2']['tmp_name'],"item2/". $_FILES['pic2']['name']);
move_uploaded_file($_FILES['pic3']['tmp_name'],"item3/". $_FILES['pic3']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',pic2='".$filename2."',pic3='".$filename3."',description='".$description."' where productkey=".$productkey;
}
elseif($filename1=='' and $filename2!='' and $filename3=='')
{
move_uploaded_file($_FILES['pic2']['tmp_name'],"item2/". $_FILES['pic2']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',pic2='".$filename2."',description='".$description."' where productkey=".$productkey;
}
elseif($filename1!='' and $filename2=='' and $filename3!='')
{
move_uploaded_file($_FILES['pic1']['tmp_name'],"item1/". $_FILES['pic1']['name']);
move_uploaded_file($_FILES['pic3']['tmp_name'],"item3/". $_FILES['pic3']['name']);
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."', pic1='".$filename1."',pic3='".$filename3."', description='".$description."'productkey=".$productkey;
}
else
{
$query="update products set categorykey='".$categorykey."',subcategorykey='".$subcategorykey."',subsubcategorykey='".$subsubcategorykey."',productname='".$productname."',description='".$description."'  where productkey=".$productkey;
}
           mysqli_query($connection,$query);
          
                    
mysqli_close($connection);

header("location:products.php");

 
   
?>