
<?php
include('../includes/connection.php');
$id=$_GET['id'];
$sql="select * from product_add where id='$id'";
$result=mysqli_query($con,$sql);
$data=mysqli_fetch_assoc($result);
?>
<?php
include('../includes/sidebar.php');
include('../includes/header.php');
?>

  <!-- [ Main Content ] start -->
  <div class="pc-container">
    <div class="pc-content">
      <!-- [ breadcrumb ] start -->
      <div class="page-header">
        <div class="page-block">
          <div class="page-header-title">
            <h5 class="mb-0 font-medium">Sample Page</h5>
          </div>
          <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="../dashboard/index.html">Home</a></li>
            <li class="breadcrumb-item"><a href="javascript: void(0)">Other</a></li>
            <li class="breadcrumb-item" aria-current="page">Sample Page</li>
          </ul>
        </div>
      </div>
      <!-- [ breadcrumb ] end -->


      <!-- [ Main Content ] start -->

      <div class="grid grid-cols-12 gap-x-6">
        <!-- [ sample-page ] start -->
        <div class="col-span-12">
          <div class="card">
            <div class="card-header">
              <h5>Hello card</h5>
            </div>
            <div class="card-body">
              <div class="container">
    <div class="row justify-content-center align-items-center">
        <div class="col-sm-6">
            <div class="modal-body">
       <form action=""method="post" enctype="multipart/form-data">
        <div class="mb-3">
          <img src="<?php echo$data['image'] ?>" alt="" style="height:100px;width:100px;">
        </div>
        <div class="mb-3">
    <label class="form-label">Image</label>
    <input type="file" class="form-control"  name="image" >
      <input type="hidden" class="form-control"  name="old_image" value="<?php echo $data['image'] ?>">
  </div>
          <div class="mb-3">
    <label class="form-label">Name</label>
    <input type="text" class="form-control"  placeholder="Enter product name" name="name" value="<?php echo$data['name'] ?>">
  </div>
  <div class="mb-3">
    <label class="form-label">Price 1</label>
    <input type="text" class="form-control"  placeholder="Enter price 1" name="price1" value="<?php echo $data['price_1'] ?>">
  </div>
   <div class="mb-3">
    <label  class="form-label">Price 2</label>
    <input type="text" class="form-control"  placeholder="Enter price 2"name="price2" value="<?php echo $data['price_2'] ?>">
  </div>
  <div class="mb-3">
    <label  class="form-label">Quantity</label>
    <input type="text" class="form-control"  placeholder="Enter quantity"name="quantity" value="<?php echo $data['quantity'] ?>">
  </div>
    <div class="mb-3">
    <label  class="form-label">Description</label>
   <textarea id=""class="form-control" name="description"><?php echo$data['description'] ?></textarea>
  </div>
  <div class="modal-footer">

        <button type="submit" class="btn btn-primary" name="submit">Save changes</button>
      </div>
</form>
      </div>
        </div>
    </div>
</div>
            </div>
          </div>

        </div>
        <!-- [ sample-page ] end -->
      </div>
      <!-- [ Main Content ] end -->
    </div>
  </div>
  <!-- [ Main Content ] end -->
 <?php

include('../includes/footer.php');
?>
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$price1=$_POST['price1'];
$price2=$_POST['price2'];
$quantity=$_POST['quantity'];
$description=$_POST['description'];
$filename=$_FILES['image']['name'];
$tempname=$_FILES['image']['tmp_name'];
$folder="images/".$filename;
$old_image=$_POST['old_image'];
if($filename=="")
{
  $folder=$old_image;
}


    $sql="update product_add set image='$folder',name='$name',price_1='$price1',price_2='$price2',quantity='$quantity',description='$description' where id='$id'";

$result=mysqli_query($con,$sql);
if ($result) {
  if($filename!="")
  {
    move_uploaded_file($tempname,$folder);
  }
		echo"<script> alert('updated successfully');window.location.href='product.php';</script>";
	}
	else{
		echo"<script> alert('updated unsuccessfully');window.location.href='product.php';</script>";
	}
}
?>