<?php

?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>

        function showcategory(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        };
        xmlhttp.open("GET","sortbycategory.php?q="+str,true);
        xmlhttp.send();
    }
}

</script>
    </head>
    <body>
          <?php
include("connection.php");
$productkey=@$_GET['productkey'];

$query="SELECT * FROM products inner join category on products.categorykey=category.categorykey inner join subcategory on products.subcategorykey=subcategory.subcategorykeyinner join subsubcategory on products.subsubcategorykey=subsubcategory.subsubcategorykey where products.productkey=".$productkey;

$records=$records=mysqli_query($connection,$query);

 $row2=@mysqli_fetch_array($records);

  
      
?>
                                    <form action="insertproduct.php" method="post" class="assessment-form" enctype="multipart/form-data">
                                        
                                        <div class="form-group">
                   <input type="hidden" autocomplete="off"  class="form-control" name="categorykey" value="<?php echo  $row2["categorykey"];   ?>" />
                 
                 <?php
include("connection.php");
$query="select * from category";
$records=$records=mysqli_query($connection,$query);
?>
 <select class="form-control" required name="categorykey" onchange="showcategory(this.value)">
      <option value="" selected = 'selected'>Select Category Name</option>
  
    
 <?php
    while($row=mysqli_fetch_array($records))    
    {
 
       
         if($row2['categorykey']==$row['categorykey'])
        {
            echo "<option value='".$row["categorykey"]."' >".$row["categoryname"]."</option>";
        }
        else 
        {
             echo "<option value='".$row["categorykey"]."'>".$row["categoryname"]."</option>";
        }

               
 
    }
 
    ?>


 
</select>   

                                        <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>
                                        </div>
                                        
                                         <div class="form-group">
                                           <select class="form-control" required name="SubCategoryKey"  id="txtHint">
	        <option value="">Select  Sub Category</option>
	        </select>
                                        </div>

                                         <div class="form-group">
                                            <input type="text" name="tname"  placeholder="Sub-Sub-Category Name" required>
                                        </div>
                                         <div class="form-group">
                                            <input type="text" name="tname"  placeholder="Product Name" required>
                                        </div>

                                         <div class="form-group">
                                            <input type="file" name="image1" required>
                                        </div>
                                         <div class="form-group">
                                            <input type="file" name="image2" required>
                                        </div>

                                         <div class="form-group">
                                            <input type="file" name="image3" required>
                                        </div>

                                       <div class="form-group">
                                            <textarea name="message" maxlength="350" placeholder="Description"></textarea>
                                        </div>
                                        <div class="form-group">
                                            <button type="submit" class="theme-btn-two"><i class="flaticon-send"></i>SUBMIT</button>
                                        </div>
                                    </form>
    </body>
</html>
