<?php 
require_once '../config/db.php';
require_once '../config/database.class.php';
require_once '../config/functions.php';
$d = new database($db_config);

// function productdetails($conn,$id){
//     $sql="SELECT * FROM subcategory WHERE id='$id' ";
//   $res=mysqli_query($conn,$sql);
//   $row=mysqli_fetch_assoc($res);
//   return $row;
// }


if(isset($_POST)){
   	$post  =$_POST;
    $catid = $_POST['catid'];
   $product = $_POST['product'];
    $description = $_POST['description'];

//   $category= $_POST['category'];
//   $dbcategory= $_POST['dbcategory'];
   
//               if(!empty($category)){
//                   $cat= $category;
//               }
//               else{
//                   $cat = $dbcategory;
//               }

   $image= $_FILES['image']['name'];
   $dbimage=$_POST['dbimage'];
        
  
//   $specification= $_POST['specification'];
   
//   if(!empty($image)){
//       $img = $image;
//       $folder="uploads/";
//       $path= $folder.basename($img);
//       move_uploaded_file($_FILES['image']['tmp_name'],$path);
//    
//   }
//   else{
//       $img= $dbimage;
//   }
  
    
    if(!empty($_FILES['image']['name']))
    {
         $img = $image;
        $folder="uploads/";
     $path= $folder.basename($img);
      move_uploaded_file($_FILES['image']['tmp_name'],$path);
      
      
       $file_url = $path.$img;
        echo getResponse('error','Please choose a file');
        die;
    }
    else 
    {
       
        $img = $dbimage;

    }
	$query = "UPDATE subcategory SET catid='".$catid."',product='".$product."',description='".$description."',image='".$img."' WHERE id=$id";

// 		 if(!empty($image))
	
//         { 
          
//             $query .= " , image='".$file_url."' ";
          
//         }
        
//          $query .= " WHERE id=$id";
         
        $executeQuery = $d->updateQuery($query);
       
        
       if($executeQuery){
   
        	echo getResponse('success','Data updated successfully');
        	  ?>
               <script>
           alert("product updated");
          
       </script>	 
       <?php 
        }else{
        	echo getResponse('error','Something went wrong, please try later!');
        }
}

?>
